function ajaxGallery(xml){alert(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){var photo=$('gallery_image');var photoBox=$('gallery_box');var photoDescription=$('gallery_description');var loadingImg=$('loading');var preLoader=[];var galleryMenu=$el('gallery_menu','a','/^(diapo)/');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();imagesLoader.onload=function(){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]});this.loader();}.bind(this),100);}.bind(this);imagesLoader.src=srcPhoto;}}
function slideDiapo(){var galleryMenu=$('gallery_slide');var topArrow=$('top_arrow');var bottomArrow=$('bottom_arrow');var topPosition=findPos(galleryMenu).top;var maxHeight=Window.height()-topPosition;setStyles(galleryMenu,{'overflow':'hidden','height':(maxHeight-50)+'px'});var scrollFx=new scrollBox();this.set=function(){maxHeight=Window.height()-topPosition;setStyles(galleryMenu,{'overflow':'hidden','height':(maxHeight-50)+'px'});topArrow.style.display=(galleryMenu.scrollHeight>(maxHeight-50))?'block':'none';bottomArrow.style.display=(galleryMenu.scrollHeight>(maxHeight-50))?'block':'none';scrollFx.set(galleryMenu);}
addEvent(window,'resize',function(event,fnc){fnc.set()},this);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(){for(var pos in move)this.move(pos);}.bind(this),30);}};this.move=function(pos){if(this.slide[pos]+this.increase[pos]<0){this.stop();this.el.scrollTop=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.scrollTop=this.limit[pos];}else{this.slide[pos]+=this.increase[pos];this.el.scrollTop=this.slide[pos];}}
this.stop=function(){clearInterval(this.timer);this.timer=false;}}
function slideShow(){var cOpacity=1,nOpacity=0,current=0,nIndex=1,imgs=[];this.options={step:3000,duration:700,align:['center','middle']};this.ajax=function(xml){var ajax=new ajaxRequest(xml);ajax.callBack(function(data,fnc){var photos=[],tagPhoto=data.responseXML.getElementsByTagName('photo');for(var i=0,l=tagPhoto.length;i<l;i++){photos.push(tagPhoto[i].firstChild.nodeValue);};fnc.setImages(photos);},this)
ajax.get();};this.initialize=function(el,options){this.box=$(el);for(var property in options)this.options[property]=options[property];this.box.position='relative';imgs[0]=$el(this.box,'img')[0];setStyles(imgs[0],{'position':'absolute'});};this.setImages=function(photos){for(var i=0,l=photos.length;i<l;i++){imgs[i+1]=addElement('img',{src:photos[i],styles:{'display':'none','position':'absolute','opacity':0,'top':'10px','left':'10px'}});this.box.appendChild(imgs[i+1]);}
if(photos.length>0)this.nextImage(1);};this.nextImage=function(numIm){nIndex=imgs[current+1]?current+1:0;var nextImage=new Image();addEvent(nextImage,'load',function(event,fnc){fnc.play(numIm);},this);nextImage.src=imgs[numIm].src;};this.play=function(numIm){imgs[numIm].style.display='block';var fx=new Fx;fx.initialize([imgs[current],imgs[nIndex]],{duration:this.options.duration,curve:['cos']});setTimeout(function(fnc){return function(){fx.start({0:{'opacity':[1,0]},1:{'opacity':[0,1]}},function(){imgs[current].style.display='none';current=nIndex;nextLoad=imgs[nIndex+1]?nIndex+1:0;fnc.nextImage(nextLoad);});}}(this),this.options.step);};}
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='';});});});