function ajaxGallery(xml){if($('gallery')){slideDiapo();var ajax=new ajaxRequest(xml);ajax.callBack(function getGallery(data){var pictureGallery=new gallery(data.responseXML)
pictureGallery.loader();});ajax.get();}};function gallery(data){$('gallery_menu').style.overflow='hidden';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=Xml(data).tag('photo_'+numIm).first;var srcPhoto=Xml(xmlPhoto).tag('src').value;var descPhoto=Xml(xmlPhoto).tag('description').value;var widthPhoto=Xml(xmlPhoto).tag('width').value;var heightPhoto=Xml(xmlPhoto).tag('height').value;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:'';setStyles(photo,{'width':widthPhoto+'px','height':heightPhoto+'px','display':'inline','opacity':0})
photo.id='gallery_image';photo.src=srcPhoto;fx.start({'opacity':[0,1]});fnc.loader();},100);},this);imagesLoader.src=srcPhoto;}}
function slideDiapo(){var galleryMenu=$('gallery_menu');var gallerySlide=$('gallery_slide');var leftArrow=$('left_arrow');var rightArrow=$('right_arrow');var leftPosition=findPos(gallerySlide).left;setStyles(galleryMenu,{'position':'relative'});setStyles(gallerySlide,{'overflow':'hidden'});var scrollFx=new scrollBox();this.set=function(){leftArrow.style.display=(gallerySlide.scrollWidth>(gallerySlide.offsetWidth+10))?'block':'none';rightArrow.style.display=(gallerySlide.scrollWidth>(gallerySlide.offsetWidth+10))?'block':'none';scrollFx.set(gallerySlide);}
addEvent(window,'resize',function(event,fnc){fnc.set()},this);this.set();addEvent(gallerySlide,'mousemove',function(event){if(!hasClass(gallerySlide,'sliding')){cursorRatio=(Cursor(event).page.x-(leftPosition+(gallerySlide.offsetWidth/2)))/80;scrollFx.init({'Left':cursorRatio});}});addEvent(gallerySlide,'mouseleave',function(event){scrollFx.stop()});addEvent(leftArrow,'mouseover',function(event){scrollFx.init({'Left':-3})});addEvent(leftArrow,'mouseout',function(event){scrollFx.stop()});addEvent(rightArrow,'mouseover',function(event){addClass(gallerySlide,'sliding');scrollFx.init({'Left':3});});addEvent(rightArrow,'mouseout',function(event){removeClass(gallerySlide,'sliding');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;}}
onDomReady(function(){$el(document,'a.lightbox').forEach(function(item){var light=new LightBox;light.initialize({lightBackOpacity:'0.5'});addEvent(item,'click',function(event){stopEvent(event);var srcImg=$el(this,'span.light_src')[0].firstChild.nodeValue;lightBoxImg(srcImg,this.title,$el(this,'img')[0].alt);});});});var LightBox=function(){this.options={loadingSrc:'images/light_loading.gif',lightBackOpacity:'0.65'};this.initialize=function(options){for(var property in options)this.options[property]=options[property];};};var Lp=LightBox.prototype={setLightBack:function(){var lightBack=addElement('div',{id:'light_back',styles:{position:'absolute',top:0,left:0,background:'#000',zIndex:10,width:'100%'},opacity:this.options.lightBackOpacity});$css("body")[0].insertBefore(lightBack,$css("body")[0].firstChild);lightBack.style.height=Window.scrollHeight()+'px';},setLightBox:function(widthBox,heightBox){var lightBox=addElement('div',{id:'light_box',styles:{visibility:'hidden'}});$css("body")[0].insertBefore(lightBox,$css("body")[0].firstChild);setStyles(lightBox,{position:'absolute',zIndex:100,width:(widthBox)+'px',height:(heightBox+20)+'px'});this.centerObj(lightBox);var lightTop=addElement('div',{id:'light_top'});lightBox.appendChild(lightTop);lightBox.onclick=function(){lightBox.style.display='none';$('light_back').style.display='none';};return lightBox;},centerObj:function(obj){var winX=Window.width(),winY=Window.height();var topPos=((winY-obj.offsetHeight)>0)?(winY-obj.offsetHeight):10;var leftPos=((winX-obj.offsetWidth)>0)?(winX-obj.offsetWidth):10;obj.style.top=(topPos/2)+Window.scrollTop()+'px';obj.style.left=(leftPos/2)+Window.scrollLeft()+'px';obj.style.visibility='visible';},showAjax:function(srcAjax){alert(this.options.loadingSrc);var objContent=document.createElement('div',{id:'light_content',styles:{width:'850px',height:'600px'}});$('light_loading').style.display='none';Lp.setLightBox(850,600);$('light_box').appendChild(objContent);$('light_top').innerHTML=srcAjax.getElementsByTagName('title')[0].firstChild.nodeValue;objContent.innerHTML=srcAjax.getElementsByTagName('content')[0].firstChild.nodeValue;},showLoading:function(){objloading=addElement('img',{id:'light_loading',src:this.options.loadingSrc});$css("body")[0].insertBefore(objloading,$css("body")[0].firstChild);setStyles(objloading,{'visibility':'hidden','position':'absolute','zIndex':'100'});objloading.src=this.options.loadingSrc;var imagesLoading=new Image();imagesLoading.onload=function(){setTimeout(function(){Lp.centerObj(objloading);},100);};imagesLoading.src=this.options.loadingSrc;},showImg:function(srcPhoto,titlePhoto,descPhoto){var imagesLoader=new Image();imagesLoader.onload=function(){setTimeout(function(){objloading.style.display='none';var objImg=addElement('img',{id:'light_photo'});$css("body")[0].insertBefore(objImg,$css("body")[0].firstChild);setStyles(objImg,{'visibility':'hidden','position':'absolute','zIndex':100});objImg.src=srcPhoto;var lightBox=Lp.setLightBox((objImg.offsetWidth+10),(objImg.offsetHeight+10));if(descPhoto){var lightDesc=addElement('div',{id:'light_description'});lightDesc.innerHTML=descPhoto;lightBox.appendChild(lightDesc);lightBox.style.height=(lightDesc.offsetHeight+lightBox.offsetHeight)+'px';lightBox.insertBefore(objImg,lightDesc);}else{lightBox.appendChild(objImg);}
if(titlePhoto)$('light_top').innerHTML=titlePhoto;setStyles(objImg,{'visibility':'visible','position':'relative'});},200);};imagesLoader.src=srcPhoto;}};function lightBoxImg(srcPhoto,titlePhoto,descPhoto){var light=new LightBox();light.setLightBack();light.showLoading();light.showImg(srcPhoto,titlePhoto,descPhoto);}
function lightBoxAjax(xmlSrc){var lightAjax=new LightBox();lightAjax.initialize({lightBackOpacity:'0.5'});lightAjax.setLightBack();lightAjax.showLoading();var ajax=new ajaxRequest(xmlSrc);ajax.callBack(setAjaxBox);ajax.get();}
function setAjaxBox(data){var setAjax=new LightBox();alert(setAjax.options.lightBackOpacity);setAjax.showAjax(data.responseXML);}