YUI.add("squarespace-gallery-slideshow",function(F){F.namespace("Squarespace");var E="Next";var A="Prev";var B="swipe";var C="fade";var D=1.5056179775280898;F.Squarespace.GallerySlideShow=Class.create({initialize:function(K){this.params=K;this.scriptId=K.scriptId;this.currentSlide=0;this.isAnimating=false;this.maxSlides=(this.params.slideTransition==B)?3:this.params.gallery.pictures.length;this.gallery=this.params.gallery;this.slides=this.params.gallery.pictures;this.totalSlides=this.params.loadCount;this.autoPlay=this.params.navigation.autoPlayEnabled;this.autoPlayConfigured=false;this.descriptionStyle=this.params.descriptionStyle;this.slideStyle=this.params.slideStyle;this.aspectX=this.params.aspectX;this.aspectY=this.params.aspectY;this.slideNavigation=this.params.slideNavigation;this.slideTransition=this.params.slideTransition;var L=F.one(this.params.targetElement);this.calculateFrameHeight(L);L.addClass("squarespace-slideshow-wrapper");if(this.slideTransition==B){L.append(F.Node.create('<div class="squarespace-slideshow" style="width:'+this.slideWidth+"px; height:"+(this.slideHeight-1)+'px;">'+'<div id="squarespace-slideshow-frame-'+K.scriptId+'" class="squarespace-slideshow-frame" style="width:'+this.slideWidth+'px;">'+'<div id="squarespace-slideshow-animated-frame-'+K.scriptId+'" style="width:'+(this.slideWidth*3)+"px; height:"+this.slideHeight+"px; margin-left:-"+this.slideWidth+'px;" class="squarespace-slideshow-animated-frame type-swipe"></div>'+'<div id="squarespace-slideshow-description-wrapper-'+K.scriptId+'" class="squarespace-slideshow-description-wrapper" style="display:none">'+'<div class="squarespace-slideshow-container"></div>'+'<div class="squarespace-slideshow-description-content">'+'<div class="squarespace-slideshow-title"><span></span></div>'+'<div class="squarespace-slideshow-description"><span></span></div>'+"</div>"+"</div>"+'<div id="frwd-'+K.scriptId+'" class="frwd fnav '+this.slideNavigation+'"></div>'+'<div id="ffwd-'+K.scriptId+'" class="ffwd fnav '+this.slideNavigation+'"></div>'+"</div>"+"</div>"));}else{if(this.slideTransition==C){L.append(F.Node.create('<div class="squarespace-slideshow" style="width:'+this.slideWidth+"px; height:"+(this.slideHeight-1)+'px;">'+'<div id="squarespace-slideshow-frame-'+K.scriptId+'" class="squarespace-slideshow-frame" style="width:'+this.slideWidth+'px;">'+'<div id="squarespace-slideshow-animated-frame-'+K.scriptId+'" style="width:'+this.slideWidth+"px; height:"+this.slideHeight+'px;" class="squarespace-slideshow-animated-frame type-fade"></div>'+'<div id="squarespace-slideshow-description-wrapper-'+K.scriptId+'" class="squarespace-slideshow-description-wrapper" style="display:none">'+'<div class="squarespace-slideshow-container"></div>'+'<div class="squarespace-slideshow-description-content">'+'<div class="squarespace-slideshow-title"><span></span></div>'+'<div class="squarespace-slideshow-description"><span></span></div>'+"</div>"+"</div>"+'<div id="frwd-'+K.scriptId+'" class="frwd fnav '+this.slideNavigation+'"></div>'+'<div id="ffwd-'+K.scriptId+'" class="ffwd fnav '+this.slideNavigation+'"></div>'+"</div>"+"</div>"));}}var I=this;F.one("#squarespace-slideshow-frame-"+K.scriptId+" #frwd-"+K.scriptId).on("click",function(){I.prevSlide(I);},I);F.one("#squarespace-slideshow-frame-"+K.scriptId+" #ffwd-"+K.scriptId).on("click",function(){I.nextSlide(I);},I);F.one("#squarespace-slideshow-frame-"+K.scriptId).on("click",function(){I.stopAutoplay(I);},I);var G=0;for(G=0;G<this.maxSlides;G++){var H;if(this.slideTransition==B){if(G===0){H=this.getPrevSlideIndex();}else{if(G===1){H=this.currentSlide;}else{H=this.getNextSlideIndex();}}}else{if(this.slideTransition==C){H=G;}}var J=F.one("#squarespace-slideshow-animated-frame-"+K.scriptId);J.append(F.Node.create('<div id="sf-'+K.scriptId+"-sl-"+H+'" style="width:'+this.slideWidth+"px; height:"+this.slideHeight+'px;" class="sf"></div>'));this.loadIndex(H,this);}},calculateFrameHeight:function(G){if(G.ancestor("#contentWrapper")){if(G.ancestor(".journal-entry")){this.slideWidth=parseInt(F.one(".journal-entry").get("clientWidth"));}else{var M=F.one("#content");var J=this.validNumber(parseInt(M.getStyle("marginLeft")));var Q=this.validNumber(parseInt(M.getStyle("marginRight")));var O=this.validNumber(parseInt(M.getStyle("paddingLeft")));var N=this.validNumber(parseInt(M.getStyle("paddingRight")));var I=this.validNumber(parseInt(M.get("clientWidth")));this.slideWidth=I-J-Q-O-N;}}else{if(G.ancestor("#sidebar1Wrapper")||G.ancestor("#sidebar2Wrapper")){var P=F.one(".section");var H=this.validNumber(parseInt(P.getStyle("marginLeft")));var K=this.validNumber(parseInt(P.getStyle("marginRight")));var L=this.validNumber(parseInt(P.getStyle("paddingLeft")));var R=this.validNumber(parseInt(P.getStyle("paddingRight")));var I=(G.ancestor("#sidebar1Wrapper"))?this.validNumber(parseInt(F.one("#sidebar1").get("clientWidth"))):this.validNumber(parseInt(F.one("#sidebar2").get("clientWidth")));this.slideWidth=I-H-K-L-R;}}if(this.slideStyle==="horizontal"){this.slideHeight=Math.round(this.slideWidth/D);}else{if(this.slideStyle==="square"){this.slideHeight=this.slideWidth;}else{if(this.slideStyle==="aspect"){this.slideHeight=Math.round(this.slideWidth/(this.aspectX/this.aspectY));}else{this.slideHeight=Math.round(this.slideWidth/D);}}}},validNumber:function(G){if(G){return G;}else{return 0;}},start:function(H){F.all("#squarespace-slideshow-animated-frame-"+this.params.scriptId+" .sf").removeClass("active");F.one("#squarespace-slideshow-animated-frame-"+this.params.scriptId+" #sf-"+this.params.scriptId+"-sl-"+this.currentSlide).addClass("active");if(!this.autoPlayConfigured&&this.autoPlay){var G=this;if(this.slideTransition==B){G.tId=F.later((G.params.navigation.slideDelay*1000),"",function(){G.animateSwipe(E,null,G);},G,true);}else{if(this.slideTransition==C){G.tId=F.later((G.params.navigation.slideDelay*1000),"",function(){G.animateFade(E,null,G);},G,true);}}this.autoPlayConfigured=true;}if(this.descriptionStyle!="hidden"){this.animateDescription(this.descriptionStyle,this.currentSlide,this.params.scriptId);}if(H){H();}},animateDescription:function(H,G,M){var I=this.slides[G];var L=F.one("#squarespace-slideshow-description-wrapper-"+M);L.setStyles({"display":"block","opacity":"0"});if(H=="title"||H=="both"){var K=F.one("#squarespace-slideshow-description-wrapper-"+M+" .squarespace-slideshow-title span");K.set("innerText",I.title);}if(H=="description"||H=="both"){var J=F.one("#squarespace-slideshow-description-wrapper-"+M+" .squarespace-slideshow-description span");J.set("innerText",I.description);}new F.Anim({node:L,to:{opacity:1},duration:0.4}).run();},loadIndex:function(G,J){var I=this.slides[G];imageLoaded=function(O,L,M,S){var N=F.one(O);var T=N.get("width");var Q=N.get("height");var P,R;if(L==="horizontal"||L==="aspect"){N.setStyle("width",M+"px");R=N.get("height");N.setStyles({"height":"auto","left":"0px","top":-J.roundNumber(((R-S)/2),2)+"px"});}else{if(L==="square"){if(T>=Q){N.setStyle("height",S+"px");P=N.get("width");N.setStyles({"width":"auto","left":-J.roundNumber(((P-M)/2),2)+"px","top":"0px"});}else{if(Q>T){N.setStyle("width",M+"px");R=N.get("height");N.setStyles({"height":"auto","left":"0px","top":-J.roundNumber(((R-S)/2),2)+"px"});}}}}};var H=F.one("#squarespace-slideshow-animated-frame-"+this.params.scriptId+" #sf-"+this.params.scriptId+"-sl-"+G);var K=F.Node.create("<img onload='imageLoaded(this, \""+this.slideStyle+'", "'+this.slideWidth+'", "'+this.slideHeight+"\")' class='slide-content'>");K.set("src","/picture/"+I.fileName+"?pictureId="+I.id);H.append(K);},prevSlide:function(G){if(G.isAnimating){return ;}if(G.slideTransition==B){G.animateSwipe(A,null,G);}else{if(G.slideTransition==C){G.animateFade(A,null,G);}}},nextSlide:function(G){if(G.isAnimating){return ;}if(G.slideTransition==B){G.animateSwipe(E,null,G);}else{if(G.slideTransition==C){G.animateFade(E,null,G);}}},stopAutoplay:function(G){G.tId.cancel();},animateSwipe:function(O,P,L){var H=L.params.scriptId;var G=L.params.navigation;var J=parseInt(F.one("#squarespace-slideshow-animated-frame-"+H).getStyle("marginLeft"));var N=(O===E)?J-parseInt(L.slideWidth):J+parseInt(L.slideWidth);var I=(O===E)?L.getPrevSlideIndex():L.getNextSlideIndex();var K=(O===E)?L.getNextSlideIndex():L.getPrevSlideIndex();var M=(O===E)?true:false;F.one("#squarespace-slideshow-animated-frame-"+H+" #sf-"+H+"-sl-"+K).addClass("active");L.a=new F.Anim({node:"#squarespace-slideshow-animated-frame-"+H,to:{marginLeft:N},duration:G.duration,easing:G.easing});L.a.on("start",function(){new F.Anim({node:F.one("#squarespace-slideshow-description-wrapper-"+H),to:{opacity:0},duration:0.3}).run();L.isAnimating=true;});L.a.on("end",function(){F.all("#squarespace-slideshow-animated-frame-"+H+" #sf-"+H+"-sl-"+I+" .slide-content").remove();var S;if(M){S=F.one("#squarespace-slideshow-animated-frame-"+H).append(F.one("#sf-"+H+"-sl-"+I));}else{var Q=document.getElementById(F.one("#squarespace-slideshow-animated-frame-"+H).get("id"));var R=document.getElementById(F.one("#squarespace-slideshow-animated-frame-"+H+" #sf-"+H+"-sl-"+I).get("id"));Q.insertBefore(R,Q.childNodes[0]);S=F.one("#squarespace-slideshow-animated-frame-"+H+" #sf-"+H+"-sl-"+I);}L.currentSlide=K;K=(O===E)?L.getNextSlideIndex():L.getPrevSlideIndex();S.set("id","sf-"+H+"-sl-"+K);F.one("#squarespace-slideshow-animated-frame-"+H).setStyle("marginLeft","-"+L.slideWidth+"px");L.loadIndex(K,L);L.start(function(){if(P){P();}});L.isAnimating=false;},L);L.a.run();},animateFade:function(O,P,N){var H=N.params.scriptId;var G=N.params.navigation;var M=(O===E)?N.getNextSlideIndex():N.getPrevSlideIndex();var I=F.one("#squarespace-slideshow-animated-frame-"+H+" #sf-"+H+"-sl-"+N.currentSlide);var L=F.one("#squarespace-slideshow-animated-frame-"+H+" #sf-"+H+"-sl-"+M);var J=new F.Anim({node:I,to:{opacity:0},duration:G.fadeDuration});J.on("start",function(){new F.Anim({node:F.one("#squarespace-slideshow-description-wrapper-"+H),to:{opacity:0},duration:0.3}).run();N.isAnimating=true;});J.run();L.setStyle("opacity","0");var K=new F.Anim({node:L,to:{opacity:1},duration:G.fadeDuration});K.on("end",function(){I.removeClass("active");L.addClass("active");if(N.descriptionStyle!="hidden"){N.animateDescription(N.descriptionStyle,M,H);}N.isAnimating=false;});K.run();N.currentSlide=M;},getPrevSlideIndex:function(G){var H;if(G){H=G;}else{H=this.currentSlide;}if(H>0){return(H-=1);}else{return this.totalSlides-1;}},getNextSlideIndex:function(G){var H;if(G){H=G;}else{H=this.currentSlide;}if(H<this.totalSlides-1){return(H+=1);}else{return 0;}},roundNumber:function(G,H){return Math.round(G*Math.pow(10,H))/Math.pow(10,H);}});});YUI().use("node","event","*",function(A){Y=A;Y.startGallerySlideShow=function(C){var C=Y.one("#"+C);var E=C.get("value");var B=Base64.decode(E);var D=YAHOO.lang.JSON.parse(B);new Y.Squarespace.GallerySlideShow({targetElement:"#squarespace-slideshow-wrapper-"+D.scriptId,pictures:D.gallery.pictures,gallery:D.gallery,scriptId:D.scriptId,descriptionStyle:D.descriptionStyle,slideStyle:D.slideStyle,aspectX:D.aspectX,aspectY:D.aspectY,slideNavigation:D.slideNavigation,slideTransition:D.slideTransition,loadCount:D.loadCount,navigation:{autoPlayEnabled:D.autoPlayEnabled,slideDelay:D.slideDelay,duration:0.5,easing:Y.Easing.easeOutStrong,fadeDuration:1}}).start();};});
