function Imageflow(_instance){this.init(_instance);};Imageflow.prototype={env:null, instance:null, init:function(_instance){this.instance=_instance;this.imageIndex=new Array();this.env=new Array();this.env['thumb-fork']=1;this.env['fired-image']=null;this.env['task-id']=null;this.env['imageflow-maxheight']=310;this.env['images-div']=null;this.env['top-image']=null;this.env['imageflow-reflection']=true;this.env['reflection_p']=0.5;this.env['focus']=4;this.env['slider_width']=14;this.env['images_cursor']='pointer';this.env['slider_cursor']='e-resize';this.env['imageflow-id']='imageflow';this.env['loading-id']='loading';this.env['images-id']='images';this.env['captions-id']='captions';this.env['scrollbar-id']='scrollbar';this.env['slider-id']='slider';this.env['caption-id']=0;this.env['new-caption-id']=0;this.env['current']=0;this.env['target']=0;this.env['mem-target']=0;this.env['is-gliding']=false;this.env['array-images']=new Array();this.env['new-slider-pos']=0;this.env['dragging']=false;this.env['dragobject']=null;this.env['dragx']=0;this.env['posx']=0;this.env['new-posx']=0;this.env['xstep']=150;this.env['max-height']=1;this.env['max-focus']=0;}, setenv:function(_key,_value){return this.env[_key]=_value;}, getenv:function(_selector){return this.env[_selector];}, unsetenv:function(_selector){delete this.env[_selector];}, loadThumbs:function(_init){if(this.imageIndex.length==0)return false;var thumbForks=this.getenv('thumb-fork');if(!thumbForks)thumbForks=3;var preID;var preload;var elem;var forks=(_init)? 0:thumbForks;for(var i=0;i < this.imageIndex.length;i++){elem=this.imageIndex[i];if(typeof elem==null)continue;this.imageIndex[i]=new Image();this.imageIndex[i].flow=stdio.getObject('flow:'+elem);if(!this.imageIndex[i].flow)continue;this.imageIndex[i].instance=this;this.imageIndex[i].onload=function(){this.instance.delayedThumbLoading(this);};var attr=this.getLongDesc(this.imageIndex[i].flow);this.imageIndex[i].src=this.getReflectionImgSrc(attr.img);forks++;if(forks >=thumbForks)break;};return false;}, delayedThumbLoading:function(_self){if(!_self)return false;var flowImg=_self.flow;if(!flowImg)return;flowImg.height=_self.height;flowImg.h=_self.height;flowImg.width=_self.width;flowImg.w=_self.width;flowImg.src=_self.src;moveTo(current);_self=null;var methodName=this.instance+'.loadThumbs()';window.setTimeout(methodName,20);return false;}, getReflectionImgSrc:function(_src){var tokens=_src.split('/');var results=[];var token=tokens[tokens.length-1];tokens[tokens.length-1]='refl_'+token;for(var i=0;i < tokens.length;i++){token=tokens[i];if(token=='categories')token='cache';results.push(token);};return results.join('/');}, imageClicked:function(_self){if(this.getenv('fired-image')!=null)return false;this.setenv('fired-image', _self);window.setTimeout(this.instance+'.afterGlide()',200);}, getLongDesc:function(_img){var result=null;var ld=_img.getAttribute('longdesc');if(!ld)return result;try{result=eval("({"+ld+"});");}catch(e){result=ld;};return result;}, afterGlide:function(){var jobID=this.getenv('task-id');if(jobID)window.clearTimeout(jobID);if(this.getenv('is-gliding')){var methodName=this.instance+'.afterGlide()';this.setenv('task-id', window.setTimeout(methodName,120));return false;};this.displayLightBoxImage();this.setenv('fired-image', null);}, displayLightBoxImage:function(){var flowImg=this.getenv('fired-image');if(!flowImg)return false;var attr=this.getLongDesc(flowImg);if(!attr)return false;var picImage=stdio.getObject('pictureImage');var toObj=stdio.getObject('subtitle-'+picImage.id);if(toObj){var subtitle=(attr.subtitle)? doyo.core.base64_decode(attr.subtitle):'&nbsp;';if(subtitle !=toObj.innerHTML){toObj.innerHTML=subtitle;};};var img=attr.img.split('/');var base=img.pop();var dir=img.join('/');if(doyo.picload){var container=false;var setSubTitle=false;doyo.picload.clickThumbnail(dir, base, attr.w, attr.h,container,setSubTitle);};return this.setOverlayVisible(true,flowImg);}, setOverlayVisible:function(_visible,_srcObject,_zIndex){var overlay=stdio.getObject('doyo-overlay');if(!overlay)return false;if(!_zIndex)_zIndex=500;if(_visible){overlay.style.zIndex=_zIndex;overlay.style.display='inline';overlay.style.visibility='visible';var endBodyDim=doyo.core.getCoords(stdio.getObject('bodys-end'));var overlayHeight=endBodyDim.y;if(!isNaN(overlayHeight)){var sh=screen.height;overlayHeight+=80;if(overlayHeight < sh){overlayHeight=sh;};};overlay.style.height=(isNaN(overlayHeight))? '250%':overlayHeight;}else{overlay.style.display='none';overlay.style.visibility='hidden';};var picImage=stdio.getObject('pictureImage');var container=stdio.getObject('drag-pictureImage');if(!container)container=picImage;if(picImage){container.style.display=overlay.style.display;container.style.visibility=overlay.style.visibility;container.style.zIndex=overlay.style.zIndex+1;if(doyo.core && doyo.dlg){if(!doyo.dlg.getenv('was-dragged')){var flowDiv=stdio.getObject(this.getenv('imageflow-id'));if(flowDiv){var fd=doyo.core.getCoords(flowDiv);container.style.top=fd.y;};if(_srcObject){var sd=doyo.core.getCoords(_srcObject);if(sd){var iw=parseInt(picImage.style.width);var x=sd.x+((sd.w-iw)/2);container.style.left=x;};};};};};return false;}};if(!doyo)var doyo=new Object();doyo.imgflow=new Imageflow('doyo.imgflow');var conf_focus=4;var conf_slider_width=14;var conf_images_cursor='pointer';var conf_slider_cursor='e-resize';var conf_imageflow='imageflow';var conf_loading='loading';var conf_images='images';var conf_scrollbar='scrollbar';var conf_slider='slider';var caption_id=0;var new_caption_id=0;var current=0;var target=0;var mem_target=0;var array_images=new Array();var new_slider_pos=0;var dragging=false;var dragobject=null;var dragx=0;var posx=0;var new_posx=0;var xstep=150;var max_height;var max_conf_focus;function step(){switch(target < current-1 || target > current+1){case true:moveTo(current+(target-current)/3);window.setTimeout(step, 50);doyo.imgflow.setenv('is-gliding',true);break;default:doyo.imgflow.setenv('is-gliding',false);break;};};function glideTo(x, new_caption_id){caption_id=new_caption_id;var topImg=img_div.childNodes.item(array_images[new_caption_id]);if(topImg !=doyo.imgflow.getenv('top-image')){doyo.imgflow.setenv('top-image',topImg);if(doyo.picload){if(topImg){var ld=doyo.imgflow.getLongDesc(topImg);if(ld){var origin=ld.img.split('/');if(origin){doyo.picload.changePictureText(origin.pop());};};};caption_div.innerHTML=(ld.subtitle)? doyo.core.base64_decode(ld.subtitle):'&nbsp;';};};target=x;mem_target=x;if(!doyo.imgflow.getenv('is-gliding')){doyo.imgflow.setenv('is-gliding',true);window.setTimeout(step, 50);};if(dragging==false){new_slider_pos=(scrollbar_width*(-(x*100/((max-1)*xstep)))/100)-new_posx;slider_div.style.marginLeft=(new_slider_pos-conf_slider_width)+'px';};};function moveTo(x){current=x;var zIndex=max;var reflection_p=doyo.imgflow.getenv('reflection_p');for(var index=0;index < max;index++){var image=img_div.childNodes.item(array_images[index]);var current_image=index*-xstep;if((current_image+max_conf_focus)< mem_target ||(current_image-max_conf_focus)> mem_target){image.style.visibility='hidden';image.style.display='none';}else{var z=Math.sqrt(10000+x*x)+100;var xs=x/z*size+size;image.style.display='inline';var new_img_h=(image.h/image.w*image.pc)/z*size;switch(new_img_h > max_height){case false:var new_img_w=image.pc/z*size;break;default:new_img_h=max_height;var new_img_w=image.w*new_img_h/image.h;break;};if(new_img_h > image.h)new_img_h=image.h;if(new_img_w > image.w)new_img_w=image.w;var new_img_top=(images_width*0.34-new_img_h)+images_top+((new_img_h/(reflection_p+1))*reflection_p);if(reflection_p < 0.5){new_img_top+=20;};image.style.left=xs-(image.pc/2)/z*size+images_left+'px';image.style.height=new_img_h+'px';image.style.width=new_img_w+'px';image.style.top=new_img_top+'px';image.style.visibility='visible';switch(x < 0){case true:zIndex++;break;default:zIndex=zIndex-1;break;};switch(image.i==caption_id){case false:image.onclick=function(){glideTo(this.x_pos, this.i);};break;default:zIndex=zIndex+1;image.onclick=image.ondblclick;break;};image.style.zIndex=zIndex;};x+=xstep;};};function refresh(onload){imageflow_div=stdio.getObject(conf_imageflow);scrollbar_div=stdio.getObject(conf_scrollbar);slider_div=stdio.getObject(conf_slider);caption_div=stdio.getObject(doyo.imgflow.getenv('captions-id'));img_div=doyo.imgflow.setenv('images-div',stdio.getObject(conf_images));images_width=img_div.offsetWidth;if(doyo.imgflow){var doyoMaxHeight=doyo.imgflow.getenv('imageflow-maxheight');if(doyoMaxHeight){var maxWidth=doyoMaxHeight*3.1;if(images_width > maxWidth){images_width=maxWidth;};};};images_top=imageflow_div.offsetTop;images_left=imageflow_div.offsetLeft;max_conf_focus=conf_focus*xstep;size=images_width*0.5;scrollbar_width=images_width*0.6;max_height=images_width*0.51;imageflow_div.style.height=max_height+'px';img_div.style.height=images_width*0.338+'px';caption_div.style.width=images_width+'px';caption_div.style.marginTop=images_width*0.03+'px';scrollbar_div.style.marginTop=images_width*0.02+'px';scrollbar_div.style.marginLeft=images_width*0.2+'px';scrollbar_div.style.width=scrollbar_width+'px';slider_div.onmousedown=function(){dragstart(this);};slider_div.style.cursor=conf_slider_cursor;var reflection_p=doyo.imgflow.getenv('reflection_p');reflection_p++;max=img_div.childNodes.length;var i=0;for(var index=0;index < max;index++){var image=img_div.childNodes.item(index);if(image.nodeType==1){array_images[i]=index;image.onclick=function(){glideTo(this.x_pos, this.i);};image.x_pos=(-i*xstep);image.i=i;if(onload==true){image.w=image.width;image.h=image.height;};switch((image.w+1)>(image.h/reflection_p)){case true:image.pc=118;break;default:image.pc=100;break;};image.ondblclick=function(){doyo.imgflow.imageClicked(this);};image.style.cursor=conf_images_cursor;i++;};};max=array_images.length;moveTo(current);glideTo(current, caption_id);};function show(id){var element=stdio.getObject(id);element.style.visibility='visible';};function hide(id){var element=stdio.getObject(id);element.style.visibility='hidden';element.style.display='none';};function ifinit(){if(stdio.getObject(conf_imageflow)){hide(conf_loading);refresh(true);show(conf_images);show(conf_scrollbar);initMouseWheel();if(!doyo.imgflow.getenv('imageflow-reflection')){doyo.imgflow.setenv('reflection_p',0.04);}doyo.core.addTrigger('mousemove', 'imgflow_drag');doyo.core.addTrigger('mouseup' , 'imgflow_dragstop');doyo.core.addTrigger('keydown' , 'shiftByKey');document.onkeydown=doyo.core.fireTrigger;window.onresize=function(){if(stdio.getObject(conf_imageflow))refresh();};};};function handle(delta){var change=false;switch(delta > 0){case true:if(caption_id >=1){target=target+xstep;new_caption_id=caption_id-1;change=true;};break;default:if(caption_id <(max-1)){target=target-xstep;new_caption_id=caption_id+1;change=true;};break;};if(change==true){glideTo(target, new_caption_id);};};function wheel(event){var delta=0;if(!event)event=window.event;if(event.wheelDelta){delta=event.wheelDelta/120;}else if(event.detail){delta=-event.detail/3;};if(delta)handle(delta);if(event.preventDefault)event.preventDefault();event.returnValue=false;};function initMouseWheel(){if(window.addEventListener)imageflow_div.addEventListener('DOMMouseScroll', wheel, false);imageflow_div.onmousewheel=wheel;};function dragstart(element){dragobject=element;dragx=posx-dragobject.offsetLeft+new_slider_pos;};function imgflow_dragstop(){dragobject=null;dragging=false;};function imgflow_drag(e){posx=document.all ? window.event.clientX:e.pageX;if(dragobject){dragging=true;new_posx=(posx-dragx)+conf_slider_width;if(new_posx <(-new_slider_pos))new_posx=-new_slider_pos;if(new_posx >(scrollbar_width-new_slider_pos))new_posx=scrollbar_width-new_slider_pos;var slider_pos=(new_posx+new_slider_pos);var step_width=slider_pos/((scrollbar_width)/(max-1));var image_number=Math.round(step_width);var new_target=(image_number)*-xstep;var new_caption_id=image_number;dragobject.style.left=new_posx+"px";glideTo(new_target, new_caption_id);};};function shiftByKey(_event){var charCode=doyo.core.getKeyCode(_event);switch(charCode){case 39:handle(-1);break;case 37:handle(1);break;case 13:var image=doyo.imgflow.getenv('top-image');if(image){doyo.imgflow.imageClicked(image);};break;case 27:return doyo.imgflow.setOverlayVisible(false);break;default:break;};};
