var gallerySet=new Class({Extends:gallery,initialize:function(b,a){this.setOptions({manualSetData:[],gallerySelector:"div.galleryElement",galleryTitleSelector:"h2",textGallerySelector:"Galleries",textShowGallerySelector:"Other Galleries",textGalleryInfo:"{0} pictures",startWithSelector:true,textShowCarousel:"{0}/{1} Pictures",carouselPreloader:false});this.setOptions(a);this.gallerySet=this.options.manualSetData;this.addEvent("onPopulated",this.createGallerySelectorTab.bind(this));this.addEvent("onPopulated",this.createGallerySelector.bind(this));this.startWithSelectorFn=this.toggleGallerySelector.pass(true,this);if(this.options.startWithSelector){this.addEvent("onGallerySelectorCreated",this.startWithSelectorFn)}this.parent(b,this.options)},populateData:function(){options=this.options;var a=$A(this.gallerySet);this.populateFrom.getElements(options.gallerySelector).each(function(b){currentGalArrayPlace=0;galleryDict={title:b.getElement(options.galleryTitleSelector).innerHTML,elements:[]};galleryDict.elements.extend(this.populateGallery(b,0));a.extend([galleryDict]);if(this.options.destroyAfterPopulate){b.dispose()}},this);this.gallerySet=a;this.galleryData=a[0].elements;this.currentGallery=-1;this.fireEvent("onPopulated")},changeGallery:function(a){if(a!=this.currentGallery){this.changeData(this.gallerySet[a].elements);this.maxIter=this.gallerySet[a].elements.length;this.currentGallery=a;this.gallerySelectorBtn.set("html",this.gallerySet[a].title);this.fireEvent("onGalleryChanged")}this.toggleGallerySelector(false)},createGallerySelectorTab:function(){this.gallerySelectorBtn=new Element("a").addClass("gallerySelectorBtn").setProperties({title:this.options.textShowGallerySelector}).set("html",this.options.textShowGallerySelector).addEvent("click",function(){this.toggleGallerySelector(true)}.bind(this)).injectInside(this.galleryElement);this.addEvent("onShowCarousel",function(){this.gallerySelectorBtn.setStyle("zIndex",10)}.bind(this));this.addEvent("onCarouselHidden",function(){this.gallerySelectorBtn.setStyle("zIndex",15)}.bind(this))},createGallerySelector:function(){this.gallerySelector=new Fx.Morph(new Element("div").addClass("gallerySelector").injectInside(this.galleryElement).setStyles({display:"none",opacity:"0"}));this.gallerySelectorTitle=new Element("h2").set("html",this.options.textGallerySelector).injectInside(this.gallerySelector.element);var a=this.galleryElement.offsetHeight-50-10-2;this.gallerySelectorWrapper=new Fx.Morph(new Element("div").addClass("gallerySelectorWrapper").setStyle("height",a+"px").injectInside(this.gallerySelector.element));this.gallerySelectorInner=new Element("div").addClass("gallerySelectorInner").injectInside(this.gallerySelectorWrapper.element);this.gallerySelectorWrapper.scroller=new Scroller(this.gallerySelectorWrapper.element,{area:100,velocity:0.3}).start();this.createGalleryButtons();this.fireEvent("onGallerySelectorCreated")},createGalleryButtons:function(){var a=((this.galleryElement.offsetWidth-30)/2)-14;this.gallerySet.each(function(e,b){var c=new Element("div").addClass("galleryButton").injectInside(this.gallerySelectorInner).addEvents({mouseover:function(f){f.button.addClass("hover")}.pass(e,this),mouseout:function(f){f.button.removeClass("hover")}.pass(e,this),click:function(f,g){this.changeGallery.pass(g,this)()}.pass([e,b],this)}).setStyle("width",a);e.button=c;var d="";if(this.options.showCarousel){d=e.elements[0].thumbnail}else{d=e.elements[0].image}new Element("div").addClass("preview").setStyle("backgroundImage","url('"+d+"')").injectInside(c);new Element("h3").set("html",e.title).injectInside(c);new Element("p").addClass("info").set("html",formatString(this.options.textGalleryInfo,e.elements.length)).injectInside(c)},this);new Element("br").injectInside(this.gallerySelectorInner).setStyle("clear","both")},toggleGallerySelector:function(a){if(a){this.gallerySelector.start({opacity:1}).element.setStyle("display","block")}else{this.gallerySelector.start({opacity:0})}},initHistory:function(){this.fireEvent("onHistoryInit");this.historyKey=this.galleryElement.id+"-gallery";if(this.options.customHistoryKey){this.historyKey=this.options.customHistoryKey()}this.history=new History.Route({defaults:[1,1],pattern:this.historyKey+"\\((\\d+)\\)-picture\\((\\d+)\\)",generate:function(a){return[this.historyKey,"(",a[0],")","-picture","(",a[1],")"].join("")}.bind(this),onMatch:function(a,b){this.changeGallery.pass(parseInt(a[0])-1,this).delay(10);if(this.gallerySelector){this.toggleGallerySelector.pass(false,this).delay(500)}this.goTo.pass(parseInt(a[1])-1,this).delay(100)}.bind(this)});updateHistory=function(){this.history.setValues([this.currentGallery+1,this.currentIter+1]);this.history.defaults=[this.currentGallery+1,this.currentIter+1]}.bind(this);this.addEvent("onChanged",updateHistory);this.addEvent("onGalleryChanged",updateHistory);this.fireEvent("onHistoryInited")}});