var IcyGallery=Class.create({version:"1.0",initialize:function(B,A){A=A||{};this.options={larghezzaDiv:199,larghezzaGal:600,altezzaGal:335,numeroDiv:0,container:"gallery",containerSlide:"ContainerSlide",controlSx:"sinistra",controlDx:"destra",classSlide:"slide",fotoFrame:"fotoFrame",fotoWidth:"400px",fotoHeight:"335px",maxPerSlide:8,itemsMarginR:"15px",thumbsHeight:"50px",thumbsWidth:"70px",thumbsMargin:"4px",imagePosition:"left",classItems:"fotogall",descrHeight:"70px",descriptionAlpha:0.6,autoStart:true,slideIntervall:5000};Object.extend(this.options,A);this.currentPhoto=1;this.currentSlide=0;$(B).setStyle({border:"1px #D2D0D1 solid",width:this.options.larghezzaGal+"px",height:this.options.altezzaGal+"px",position:"relative","text-align":"left",overflow:"hidden"});this.fotoFrame=new Element("div",{"class":this.options.fotoFrame});this.fotoFrame.setStyle({width:this.options.fotoWidth,height:this.options.fotoHeight,"float":this.options.imagePosition,overflow:"hidden",margin:"0",padding:"0",textAlign:"center"});this.fotoFrame.setStyle({backgroundImage:"url('css/images/loading.gif')",backgroundPosition:"center center",backgroundRepeat:"no-repeat"});this.description=new Element("div",{"class":"descr"});if(this.options.imagePosition=="left"){this.description.setStyle({position:"absolute",bottom:"-"+this.options.descrHeight,height:this.options.descrHeight,left:"0"})}else{this.description.setStyle({position:"absolute",bottom:"-"+this.options.descrHeight,height:this.options.descrHeight,right:"0"})}$(B).insert(this.fotoFrame).insert(this.description);this.descrL=parseInt(this.options.fotoWidth.replace("px",""))-(parseInt(this.description.getStyle("padding-left").replace("px",""))+parseInt(this.description.getStyle("padding-right").replace("px","")));this.description.setStyle({width:this.descrL+"px"});this.gallery=new Element("div",{"class":this.options.container});this.gallery.setStyle({width:this.options.larghezzaDiv+"px",height:"100%",overflow:"hidden","float":"left",position:"relative",margin:"0",padding:"0"});this.containerSlide=new Element("div",{"class":this.options.containerSlide});this.gallery.insert(this.containerSlide);$(B).insert(this.gallery);if(!$(this.options.controlSx)){this.controlSX=new Element("div",{id:this.options.controlSx});this.controlSX.setStyle({backgroundImage:"url('css/images/left.png')",position:"absolute",left:"4px",bottom:"0",width:"25px",height:"28px",cursor:"pointer"});this.gallery.insert(this.controlSX)}if(!$(this.options.controlDx)){this.controlDX=new Element("div",{id:this.options.controlDx});this.controlDX.setStyle({backgroundImage:"url('css/images/right.png')",position:"absolute",right:"4px",bottom:"0",width:"25px",height:"28px",cursor:"pointer"});this.gallery.insert(this.controlDX)}this.numberInsert=0;this.totFoto=0;$(B).descendants("img").each(function(C){if(C.nodeName=="IMG"){if(this.numberInsert==0){this.margin=new Element("div",{"class":"itemsMargin"});if(this.options.imagePosition=="left"){this.margin.setStyle({"float":"left",height:"100%",marginRight:this.options.itemsMarginR,width:"4px"})}else{this.margin.setStyle({"float":"right",height:"100%",marginLeft:this.options.itemsMarginR,width:"4px"})}this.slide=new Element("div",{"class":this.options.classSlide}).insert(this.margin);this.slide.setStyle({textAlign:"left"});this.containerSlide.insert(this.slide);Event.observe(this.slide,"click",function(D){this.findPosition(D)}.bind(this))}this.totFoto++;if(this.numberInsert<this.options.maxPerSlide){this.slide.insert(C);C.setStyle({opacity:0.6});if(this.first==null){this.first=C}C.setStyle({margin:this.options.thumbsMargin,width:this.options.thumbsWidth,height:this.options.thumbsHeight,cursor:"pointer",display:"inline"});this.numberInsert++;if(this.numberInsert==this.options.maxPerSlide){this.numberInsert=0}}}}.bind(this));$$("."+this.options.classSlide).each(function(C){this.options.numeroDiv++;$(C).setStyle({width:this.options.larghezzaDiv+"px",height:"100%","float":"left"})}.bind(this));this.containerSlide.setStyle({width:(this.options.larghezzaDiv*this.options.numeroDiv)+"px",height:"100%",left:"0px",position:"relative"});$$("."+this.options.classItems).each(function(C){Event.observe(C,"click",function(){this.showImage(C)}.bind(this))}.bind(this));$(this.options.controlSx).show();$(this.options.controlDx).show();Event.observe($(this.options.controlDx),"click",function(){this.moveDx()}.bind(this));Event.observe($(this.options.controlSx),"click",function(){this.moveSx()}.bind(this));this.slideShow();if(this.options.autoStart){window.setInterval(this.slideShow.bind(this),this.options.slideIntervall)}},findPosition:function(A){this.imgPosition=0;this.x=Event.findElement(A);if(this.x.nodeName=="IMG"){while(this.x.nodeName=="IMG"){this.imgPosition++;this.x=this.x.previous()}this.s=this.x.up();this.slidePosition=-1;while(this.s!=null&&this.s.hasClassName(this.options.classSlide)){this.s=this.s.previous();this.slidePosition++}this.currentPhoto=++this.imgPosition;if(this.imgPosition>$$("."+this.options.classSlide)[this.slidePosition].childElements().length-1){this.currentSlide=this.slidePosition;this.currentPhoto=1;if(this.currentSlide>$$("."+this.options.classSlide).length-1){this.currentSlide=0}this.move=true}else{this.currentSlide=this.slidePosition}}},moveSx:function(){if(this.containerSlide.getStyle("left").replace("px","")<0){var B=new FX.Element(this.containerSlide).animate({left:(1*this.containerSlide.getStyle("left").replace("px",""))+this.options.larghezzaDiv})}else{var B=new FX.Element(this.containerSlide).animate({left:0})}var A=Math.abs($(this.containerSlide).getStyle("left").replace("px",""));if(A==this.options.larghezzaDiv*(this.options.numeroDiv-1)){B.play();this.move=false;this.currentSlide--;this.currentPhoto=1}else{var C=(this.options.larghezzaDiv*(this.options.numeroDiv-1))%A;if(C%this.options.larghezzaDiv==0){B.play();this.move=false;this.currentSlide--;this.currentPhoto=1}}},moveDx:function(){if(this.containerSlide.getStyle("left").replace("px","")>-(this.options.larghezzaDiv*(this.options.numeroDiv-1))){var B=new FX.Element(this.containerSlide).animate({left:this.containerSlide.getStyle("left").replace("px","")-this.options.larghezzaDiv});this.rewind=false}else{var B=new FX.Element(this.containerSlide).animate({left:0});this.rewind=true}var A=Math.abs(this.containerSlide.getStyle("left").replace("px",""));if(A==0){B.play();this.move=false;if(this.rewind){this.currentSlide=0}else{this.currentSlide++}this.currentPhoto=1}else{var C=(this.options.larghezzaDiv*(this.options.numeroDiv-1))%A;if(C%this.options.larghezzaDiv==0){B.play();this.move=false;if(this.rewind){this.currentSlide=0}else{this.currentSlide++}this.currentPhoto=1}}},slideShow:function(){if(this.move){this.moveDx();this.move=false}this.showImage($$("."+this.options.classSlide)[this.currentSlide].down(this.currentPhoto));this.currentPhoto++;if(this.currentPhoto>$$("."+this.options.classSlide)[this.currentSlide].childElements().length-1){this.move=true}},showImage:function(A){$$("."+this.options.classItems).each(function(C){C.setStyle({opacity:0.6});if(C==A){C.setStyle({opacity:1})}});this.fotoFrame.update("");var B=new Image();B.onLoad=this.loader(A);B.src=$(A).getAttribute("longdesc")},loader:function(A){this.img=new Image();this.img.src=$(A).getAttribute("longdesc");$(this.img).setStyle({opacity:0.0001});this.fotoFrame.update(this.img);var B=new FX.Element(this.img).animate({opacity:"1"}).play();if($(A).getAttribute("alt")){this.description.show();this.description.update($(A).getAttribute("alt"));this.description.show();var B=new FX.Element(this.description).animate({bottom:0,opacity:this.options.descriptionAlpha}).setOptions({duration:1000,transition:FX.Transition.easeOutBounce});B.play()}else{this.description.hide();this.description.setStyle({bottom:"-"+this.options.descrHeight})}}});
