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(){changeClassById(document,'mouseenter',['td#open','green','darkgreen'],['show','hide','show']);changeClassById(document,'mouseleave',['td#open','green','darkgreen'],['show','hide','show'],true);var objBody=$css('body')[0];var toolTip=addElement('div',{'id':'tooltip','style':{'visibility':'hidden'}});objBody.insertBefore(toolTip,objBody.firstChild);document.onmousemove=function(e){var cursor=Cursor(e);limitX=toolTip.offsetWidth;limitY=toolTip.offsetHeight;toolTip.style.left=(((Window.width()-cursor.client.x)-30)<limitX)?cursor.page.x-limitX-10+"px":cursor.page.x+12+"px";toolTip.style.top=(((Window.height()-cursor.client.y)-20)<limitY)?cursor.page.y-limitY-10+"px":cursor.page.y+25+"px";}
$css('.tooltip').forEach(function(item){addEvent(item,'mouseover',function(){var toolNode=$el(item,'div.tip')[0];if(toolNode){toolClone=toolNode.cloneNode(true);toolTip.appendChild(toolClone);toolClone.style.display="block";toolTip.style.visibility="visible";}});addEvent(item,'mouseout',function(){setStyles(toolTip,{'visibility':'hidden','left':'-1000px'});toolTip.innerHTML='';});});});