var $removeEvents=function(A,C){if(!A.events){return A}if(C){if(!A.events[C]){return A}for(var B in A.events[C]){A.removeEvent(C,B)}A.events[C]=null}else{for(var D in A.events){A.removeEvents(D)}A.events=null}return A};var gallery=new Class({initialize:function(C,B){this.setOptions({showArrows:true,showInfopane:true,embedLinks:true,fadeDuration:800,timed:true,delay:8000,preloader:true,manualData:[],populateData:true,elementSelector:"div.imageElement",titleSelector:"h3",subtitleSelector:"p",linkSelector:"a.open",imageSelector:"img.full",slideInfoZoneOpacity:0.7,destroyAfterPopulate:true,baseClass:"jdGallery",withArrowsClass:"withArrows",maxWidth:430,maxHeight:280},B);this.fireEvent("onInit");this.currentIter=0;this.lastIter=0;this.maxIter=0;this.galleryElement=C;this.galleryData=this.options.manualData;this.galleryInit=1;this.galleryElements=Array();this.galleryElement.addClass(this.options.baseClass);if(this.options.populateData){this.populateData()}C.style.display="block";if(this.options.embedLinks){this.currentLink=new Element("a").addClass("open").setProperties({href:"#",title:""}).injectInside(C);this.currentLink.setStyle("display","block")}this.constructElements();if(this.options.showInfopane){this.initInfoSlideshow()}if((data.length>1)&&(this.options.showArrows)){var D=new Element("a",{title:"Previous Image"}).addClass("rotatorleftArr").addEvent("click",this.prevItem.bind(this)).injectInside(this.slideInfoPane);D.setHTML("&nbsp;");var A=new Element("a",{title:"Next Image"}).addClass("rotatorRightArr").addEvent("click",this.nextItem.bind(this)).injectInside(this.slideInfoPane);A.setHTML("&nbsp;");this.galleryElement.addClass(this.options.withArrowsClass)}this.loadingElement=new Element("div").addClass("loadingElement").injectInside(C);this.doSlideShow(1)},populateData:function(){currentArrayPlace=this.galleryData.length;options=this.options;data=this.galleryData;this.galleryElement.getElements(options.elementSelector).each(function(A){elementDict={image:A.getElement(options.imageSelector).getProperty("src"),width:A.getElement(options.imageSelector).getProperty("width"),height:A.getElement(options.imageSelector).getProperty("height"),number:currentArrayPlace};if((options.showInfopane)|(options.showCarousel)){Object.extend(elementDict,{title:A.getElement(options.titleSelector).innerHTML,description:A.getElement(options.subtitleSelector).innerHTML})}if(options.embedLinks){Object.extend(elementDict,{link:A.getElement(options.linkSelector).href||false,linkTitle:A.getElement(options.linkSelector).title||false})}data[currentArrayPlace]=elementDict;currentArrayPlace++;if(this.options.destroyAfterPopulate){A.remove()}});this.galleryData=data;this.fireEvent("onPopulated")},constructElements:function(){el=this.galleryElement;this.maxIter=this.galleryData.length;var C;for(i=0;i<this.galleryData.length;i++){var A=new Element("div").addClass("slideElement").setStyles({position:"absolute",left:"0px",right:"0px",margin:"0px",padding:"0px",opacity:"0",width:this.options.maxWidth+"px"}).injectInside(el);if((this.galleryData[i].width<this.options.maxWidth)&&(this.galleryData[i].height<this.options.maxHeight)){newHeight=this.galleryData[i].height;newWidth=this.galleryData[i].width}else{ratio=this.galleryData[i].width/this.galleryData[i].height;newWidth=Math.round(this.options.maxHeight*ratio);newHeight=this.options.maxHeight;if(newWidth>this.options.maxWidth){ratio=this.galleryData[i].width/this.options.maxWidth;newHeight=this.galleryData[i].height/ratio;newWidth=this.options.maxWidth}}var C=new Element("img",{src:this.galleryData[i].image,height:newHeight,width:newWidth});C.injectInside(A);var B=new Fx.Style(A,"opacity",{duration:this.options.fadeDuration});this.galleryElements[parseInt(i)]=B}},destroySlideShow:function(A){var B=A.className;var C=new Element("div").addClass("myClassName");A.parentNode.replaceChild(C,A)},startSlideShow:function(){this.fireEvent("onStart");this.loadingElement.style.display="none";this.lastIter=this.maxIter-1;this.currentIter=0;this.galleryInit=0;this.galleryElements[parseInt(this.currentIter)].set(1);if(this.options.showInfopane){this.showInfoSlideShow.delay(10,this)}this.prepareTimer()},nextItem:function(){this.fireEvent("onNextCalled");this.nextIter=this.currentIter+1;if(this.nextIter>=this.maxIter){this.nextIter=0}this.galleryInit=0;this.goTo(this.nextIter)},prevItem:function(){this.fireEvent("onPreviousCalled");this.nextIter=this.currentIter-1;if(this.nextIter<=-1){this.nextIter=this.maxIter-1}this.galleryInit=0;this.goTo(this.nextIter)},goTo:function(A){this.clearTimer();this.changeItem.delay(500,this,A);this.prepareTimer()},changeItem:function(A){this.fireEvent("onStartChanging");this.galleryInit=0;if(this.currentIter!=A){for(i=0;i<this.maxIter;i++){if((i!=this.currentIter)){this.galleryElements[i].set(0)}}if(A>this.currentIter){this.galleryElements[A].custom(1)}else{this.galleryElements[A].set(1);this.galleryElements[this.currentIter].custom(0)}this.currentIter=A}this.doSlideShow.bind(this)();this.fireEvent("onChanged")},clearTimer:function(){if(this.options.timed){$clear(this.timer)}},prepareTimer:function(){if(this.options.timed){this.timer=this.nextItem.delay(this.options.delay,this)}},doSlideShow:function(A){if(this.galleryInit==1){imgPreloader=new Image();imgPreloader.onload=function(){this.startSlideShow.delay(10,this)}.bind(this);imgPreloader.src=this.galleryData[0].image}else{if(this.options.showInfopane){if(this.options.showInfopane){this.showInfoSlideShow.delay((10+this.options.fadeDuration),this)}}}},initInfoSlideshow:function(){this.slideInfoPane=new Element("div").addClass("slideInfoPane").injectInside($(this.galleryElement));this.sideInfoText=new Element("div").setProperty("id","imageLink").injectInside($(this.slideInfoPane))},showInfoSlideShow:function(){this.fireEvent("onShowInfopane");newHTML="<h2>"+this.galleryData[this.currentIter].title+"</h2> &nbsp;<span class='imageSubDesc'>"+this.galleryData[this.currentIter].description+"</span>";$("imageLink").setHTML(newHTML)}});gallery.implement(new Events);gallery.implement(new Options);