var EcoSlider=new Class({Implements:[Events,Options],options:{fx:{slider:{link:"cancel",transition:Fx.Transitions.Expo.easeOut,property:"margin-left"}},opcaoLink:false},initialize:function(C,B){this.setOptions(B);this.container=$(C)||$$(C)[0];this.legendaContainer=this.container.getElement(".eco-legenda");this.imgContainer=this.container.getElement(".eco-img-grd");this.arrowLeft=this.container.getElement(".eco-slider-imgs-seta-esq");this.arrowRight=this.container.getElement(".eco-slider-imgs-seta-dir");this.bigArrowLeft=this.container.getElement(".eco-container-seta-grd-esq");this.bigArrowRight=this.container.getElement(".eco-container-seta-grd-dir");this.disabledClass="eco-slider-imgs-seta-desabilitado";var D=this.container.getElement(".eco-slider-imgs").getElement("ul"),A=this.container.getElement(".eco-slider-imgs");this.lis=D.getElements("li");this.as=D.getElements("a");this.imgs=D.getElements("img");this.cachedImgs=[];this.liWidth=this.lis[0].getWidth()+this.lis[0].getStyle("margin-left").toInt()+this.lis[0].getStyle("margin-right").toInt();this.numberVisibleLis=Math.ceil(A.getWidth()/this.liWidth);this.sliderFx=new Fx.Tween(D,this.options.fx.slider);this.liCounter=0;this.maxCounterValue=this.lis.length-this.numberVisibleLis;this.showVisibleImgs();this.createLegenda();this.setImgsClickEvent();this.setBigArrowsClickEvent();this.setArrowsEvent();if(this.options.opcaoLink){this.setOpcaoLink()}},showImg:function(A){if(!this.imgs[A].get("src")){this.imgs[A].set("src",this.imgs[A].get("longdesc"))}},showVisibleImgs:function(){var A=Math.min(this.numberVisibleLis,this.imgs.length);for(var B=A;B--;){this.showImg(B)}},setBigImg:function(){var A=this.imgContainer.getElements("img");if(A.length){A.dispose()}if(!this.cachedImgs[this.currentImg]){var B=new Element("img");B.store("img-index",this.currentImg);B.addEvent("load",function(C){B.inject(this.imgContainer,"top");this.cachedImgs[B.retrieve("img-index")]=B}.bind(this));B.set("src",this.as[this.currentImg].get("href"))}else{this.cachedImgs[this.currentImg].inject(this.imgContainer)}},setImgsClickEvent:function(){var A=this;this.as.each(function(C,B){C.addEvent("click",function(){if(!C.hasClass("eco-current-img")){A.currentImg=B;A.changeImg()}return false})})},setHoverClass:function(){this.as.each(function(A){A.removeClass("eco-current-img")});this.as[this.currentImg].addClass("eco-current-img")},setArrowsEvent:function(){this.arrowLeft.addClass(this.disabledClass);if(this.imgs.length<=this.numberVisibleLis){this.arrowRight.addClass(this.disabledClass)}this.arrowLeft.addEvent("click",function(){this.leftArrowClickEvent();return false}.bind(this));this.arrowRight.addEvent("click",function(){this.rightArrowClickEvent();return false}.bind(this))},leftArrowClickEvent:function(){if(this.liCounter>0){this.arrowRight.removeClass(this.disabledClass);this.liCounter--;this.sliderFx.start(-(this.liCounter*this.liWidth));if(this.liCounter==0){this.arrowLeft.addClass(this.disabledClass)}}},rightArrowClickEvent:function(){if(this.liCounter<this.maxCounterValue){this.arrowLeft.removeClass(this.disabledClass);this.showImg(this.liCounter+this.numberVisibleLis);this.liCounter++;this.sliderFx.start(-(this.liCounter*this.liWidth));if(this.liCounter==this.maxCounterValue){this.arrowRight.addClass(this.disabledClass)}}},changeImg:function(){this.setBigImg();this.setLegenda();this.setHoverClass();this.bigArrowLeft.setStyle("display",(this.currentImg==0)?"none":"block");this.bigArrowRight.setStyle("display",(this.currentImg==this.imgs.length-1)?"none":"block");if(this.options.opcaoLink){this.setOpcaoLinkHref()}},setBigArrowsClickEvent:function(){this.currentImg=0;this.setBigImg();this.setLegenda();this.setHoverClass();this.bigArrowLeft.setStyle("display","none");this.bigArrowLeft.addEvent("click",function(A){if(this.currentImg>0){this.currentImg--;this.changeImg()}if(this.currentImg<this.liCounter){this.leftArrowClickEvent()}return false}.bind(this));this.bigArrowRight.addEvent("click",function(A){if(this.currentImg<this.imgs.length){this.bigArrowLeft.setStyle("display","block");this.currentImg++;this.changeImg()}if(this.currentImg>=this.numberVisibleLis+this.liCounter){this.rightArrowClickEvent()}return false}.bind(this))},setOpcaoLinkHref:function(){this.linkOpcao.set("href",this.imgs[this.currentImg].get("data-opcao-link"))},setOpcaoLink:function(){var A=this.container.getElement(".eco-container-img-grd");this.linkOpcao=new Element("a",{"class":"eco-link-opcao","title":this.options.opcaoLink,"html":this.options.opcaoLink}).inject(A);this.setOpcaoLinkHref();A.addEvents({"mouseenter":function(){this.linkOpcao.setStyle("visibility","visible")}.bind(this),"mouseleave":function(){this.linkOpcao.setStyle("visibility","hidden")}.bind(this)})},createLegenda:function(){this.legTitle=new Element("strong");this.legText=new Element("p");this.legendaContainer.adopt(this.legTitle,this.legText)},setLegenda:function(){this.legTitle.set("html",this.as[this.currentImg].get("title"));this.legText.set("html",this.as[this.currentImg].get("rel"))}})
