function gallery(data){var photo=$('gallery_image');var photoBox=$('gallery_box');var photoDescription=$('gallery_description');var loadingImg=$('loading');var preLoader=[];var galleryMenu=$el($('gallery_menu'),'a');addEvents(galleryMenu,'click',function(event,fnc){galleryMenu.forEach(function(img,i){preLoader[i].src='';});fnc.displayImage(this.id.replace('diapo_',''));stopEvent(event);},this);this.loader=function(){galleryMenu.forEach(function(item,index){preLoader[index]=new Image();preLoader[index].src=data.getElementsByTagName('photo_'+item.id.replace('diapo_',''))[0].getElementsByTagName('src')[0].firstChild.nodeValue;});},this.displayImage=function(numIm){photo.style.display='none';loadingImg.style.display='inline';var xmlPhoto=data.getElementsByTagName('photo_'+numIm)[0];var srcPhoto=xmlPhoto.getElementsByTagName('src')[0].firstChild.nodeValue;var descPhoto=xmlPhoto.getElementsByTagName('description')[0];var widthPhoto=xmlPhoto.getElementsByTagName('width')[0].firstChild.nodeValue;var heightPhoto=xmlPhoto.getElementsByTagName('height')[0].firstChild.nodeValue;var imagesLoader=new Image();addEvent(imagesLoader,'load',function(event,fnc){setTimeout(function(){var fx=new Fx;fx.initialize(photo,{duration:800,curve:['cos']});loadingImg.style.display='none';photoDescription.innerHTML=(descPhoto)?descPhoto.firstChild.nodeValue:'';setOpacity(photo,0);photo.style.width=widthPhoto+'px';photo.style.height=heightPhoto+'px';photo.id='gallery_image';photo.src=srcPhoto;photo.style.display='inline';fx.start({'opacity':[0,1]});fnc.loader();},100);},this);imagesLoader.src=srcPhoto;}}
function slideDiapo(){var galleryMenu=$('gallery_slide');var topArrow=$('top_arrow');var bottomArrow=$('bottom_arrow');var topPosition=findPos(galleryMenu).top;setStyles(galleryMenu,{'overflow':'hidden'});var scrollFx=new scrollBox();this.set=function(){topArrow.style.display=(galleryMenu.scrollHeight>galleryMenu.offsetHeight)?'block':'none';bottomArrow.style.display=(galleryMenu.scrollHeight>galleryMenu.offsetHeight)?'block':'none';scrollFx.set(galleryMenu);}
this.set();addEvent(galleryMenu,'mousemove',function(event){cursorRatio=(Cursor(event).page.y-(topPosition+(galleryMenu.offsetHeight/2)))/80;scrollFx.init({'Top':cursorRatio});});addEvent(topArrow,'mouseover',function(event){scrollFx.init({'Top':-5})});addEvent(topArrow,'mouseout',function(event){scrollFx.stop()});addEvent(bottomArrow,'mouseover',function(event){scrollFx.init({'Top':5})});addEvent(bottomArrow,'mouseout',function(event){scrollFx.stop()});addEvent(galleryMenu,'mouseleave',function(event){scrollFx.stop()});}
function scrollBox(){this.set=function(el){this.el=el;this.timer=false;this.limit={'Top':(el.scrollHeight)-(el.offsetHeight),'Left':(el.scrollWidth)-(el.offsetWidth)}};this.init=function(move){this.slide=[];this.increase=[];for(var pos in move){this.increase[pos]=move[pos];this.slide[pos]=this.el["scroll"+pos];}
if(!this.timer){this.timer=setInterval(function(fnc){return function(){for(var pos in move)fnc.move(pos);}}(this),30);}};this.move=function(pos){if(this.slide[pos]+this.increase[pos]<0){this.stop();this.el['scroll'+pos]=0;this.slide[pos]=0;}else if(this.slide[pos]+this.increase[pos]>this.limit[pos]){this.stop();this.slide[pos]=this.limit[pos];this.el['scroll'+pos]=this.limit[pos];}else{this.slide[pos]+=this.increase[pos];this.el['scroll'+pos]=this.slide[pos];}}
this.stop=function(){clearInterval(this.timer);this.timer=false;}}
