AC.ViewMaster.CarouselViewer=Class.create(AC.ViewMaster.SlideViewer,{initialize:function($super,c,a,d,b){$super(c,a,d,b);
this._isiOS=AC.Detector.isiPad()||AC.Detector.isMobile();if(!!this.options.noCarouselForiOS&&this._isiOS){this._noCarousel=true
}if(!!this._noCarousel){this.options.shouldAnimateContentChange=false}this._scaleController=new AC.ViewMaster.CarouselViewer.ScaleController(this,this.options)
},willShow:function($super,b,c,a){if(typeof this.videoController!=="undefined"){if(this.videoController.videoIsPlaying===true){this.videoController.stop()
}}return $super(b,c,a)},didShow:function($super,a){if(typeof this.videoController!=="undefined"){if(this.options.playVideoOnSectionSwap){var b=this.videoController.hasVideo(this.currentSection);
if(b!==false){this.videoController.play(b)}}}return $super(a)},_animate:function(c,b){var a=this.view.view();
if(b==0){a.setVendorPrefixStyle("transition","none")}else{a.setVendorPrefixStyle("transition","-webkit-transform "+b+"s linear")
}a.setAttribute("left",c);if(AC.Detector.supportsThreeD()&&!(this._isiOS&&!!this.options.no3DForiOS)){a.setVendorPrefixStyle("transform","translate3d("+c+"px, 0, 0)")
}else{a.setVendorPrefixStyle("transform","translate("+c+"px, 0)")}},_animation:function(g,d,b,a,j,c){var i=g._view;
this.currentLeft=this.newLeft||i.offsetLeft||0,this.newLeft=-b.offsetLeft||0;b.setOpacity(1);
var e=this.indexOfSection(g.delegate.currentSection),f=g.delegate.previousSection?this.indexOfSection(g.delegate.previousSection):-1;
if(AC.Detector.isCSSAvailable("transition")&&AC.Detector.isCSSAvailable("transform")){this._animate(this.newLeft,c);
g._view.fire("ScaleController:Start",{incomingIndex:e,outgoingIndex:f});var h=function(k){if(k.target==i&&k.propertyName.match(/transform$/i)){i.removeVendorEventListener("transitionEnd",h,false);
g._view.fire("ScaleController:Stop");a()}};if(c>0){i.addVendorEventListener("transitionEnd",h,false)
}else{a()}}else{g._view.fire("ScaleController:Start",{incomingIndex:e,outgoingIndex:f});
return new Effect.Move(i,{x:this.newLeft-this.currentLeft,y:0,duration:c,afterFinish:function(){g._view.fire("ScaleController:Stop");
a()},queue:{scope:j}})}}});AC.ViewMaster.CarouselViewer.VideoController=Class.create({defaultOptions:{clickToPlayText:"Click to Play",closeText:"close",createCloseButton:true,closeButtonHref:"#SwapViewFirstSection"},initialize:function(a){this.options=Object.clone(this.defaultOptions);
this.options=Object.extend(this.options,a.options);this.options.usePosterframeAsVideoSectionForiPhone=!!this.options.usePosterframeAsVideoSectionForiPhone?!!AC.Detector.isMobile():false;
this.parent=a;this.parentContent=this.parent.view.view();this.viewId=this.parentContent.id||!!this.parentContent.up()?this.parentContent.up().id:"generic-id-"+(Math.random()*1000);
this.videos=[];this.videoCanBeInline=(AC.Detector.isMobile()&&!this.options.usePosterframeAsVideoSectionForiPhone)?false:true;
if(this.videoCanBeInline&&!this.options.usePosterframeAsVideoSectionForiPhone){this.container=this._createContainer();
this.parentContent.insert({after:this.container});this.blankFirstSection=this._createBlankFirstSection();
this.view=new AC.ViewMaster.Viewer([this.blankFirstSection],this.container,this.viewId+"-trigger",{silentTriggers:true,shouldAnimateContentChange:false,showPreviousOnStopMovie:true});
this._boundTespondToKeyPress=this._respondToKeyPress.bindAsEventListener(this);
document.observe("keypress",this._boundTespondToKeyPress);this.view.setDelegate(this)
}},hasVideo:function(a){return this.view.sectionWithId(a.id+"-video")||false},play:function(a,b){if(this.videoIsPlaying){return false
}if(b!==true){this.view.show(a)}this.parent.view.view().fire("AC.ViewMaster.Slideshow:stop")
},stop:function(a){if(!this.videoIsPlaying){return false}if(a!==true){this.view.showFirst()
}},addSection:function(c,b){var a={};a.section=c;a.movieLink=b;a.baseId=a.section.id;
if(!this.options.usePosterframeAsVideoSectionForiPhone){a.clickToPlaySection=this._createClickToPlay(a);
a.movieLink.insert({after:a.clickToPlaySection});if(this.videoCanBeInline){a.videoSection=this._createVideoSection(a);
if(this.options.createCloseButton){a.videoSection.insert({top:this._createCloseButton(a)})
}}}else{a.section.content.addClassName("iPhonePosterframeMoviePanel")}this.videos.push(a);
if(this.videoCanBeInline&&!this.options.usePosterframeAsVideoSectionForiPhone){a.SwapViewSection=this.view.addSection(a.videoSection)
}if(this.videoCanBeInline){a.movieLink.addClassName("movieLink")}else{a.movieLink.remove()
}if(this.options.usePosterframeAsVideoSectionForiPhone){if(this.parent.orderedSections.indexOf(a.section.id)===0){a.section.movieLink=a.movieLink;
a.section.moviePanel=new Element("div",{"class":"moviePanel"});a.section.content.insert(a.section.moviePanel);
a.section.didShow()}}return a},willShow:function(a,c,b){if(b.id===this.viewId+"-video-controller"){this.container.removeClassName("videoIsPlaying");
this.parentContent.removeClassName("videoIsPlaying");this.videoIsPlaying=false}else{this.container.addClassName("videoIsPlaying");
this.parentContent.addClassName("videoIsPlaying");this.videoIsPlaying=true}},isInView:function(d){var c=document.viewport.getScrollOffsets(),e=document.viewport.getHeight(),f=this.view.view.view(),b=f.getHeight(),a=f.cumulativeOffset()[1];
return(a>=c[1]&&Math.round(a+(b/2))<(c[1]+e))},_respondToKeyPress:function(a){if(this.isInView()){if(a.keyCode===32||a.charCode===32){var b=this.hasVideo(this.parent.currentSection);
if(this.parent.options.playVideoOnSpacebarPress===true&&b!==false){a.stop();this.play(b)
}}}},_createContainer:function(){return new Element("div")},_createBlankFirstSection:function(){return new Element("div",{id:this.viewId+"-video-controller"})
},_createClickToPlay:function(b){var a=new Element("a",{"class":"pillbutton "+this.viewId+"-trigger",href:"#"+b.baseId+"-video"}).update("<span>"+this.options.clickToPlayText+"</span><b>&gt;</b>");
if(this.videoCanBeInline){a.observe("click",function(c){this.play(b.section,true)
}.bind(this))}else{a.href=b.movieLink.href}return a},_createVideoSection:function(a){var b=new Element("div",{"class":"movie-view",id:a.baseId+"-video"});
b.insert(a.movieLink);return b},_createCloseButton:function(b){var a=new Element("a",{"class":"close "+b.baseId+"-trigger",href:this.options.closeButtonHref}).update(this.options.closeText);
a.observe("click",function(c){this.stop(true)}.bind(this));return a}});AC.ViewMaster.CarouselViewer.ScaleController=Class.create({defaultOptions:{scaleMin:0.8,scaleMax:1},initialize:function(a,b){if(!b){b={}
}this.options=Object.clone(this.defaultOptions);Object.extend(this.options,b);this.view=a;
this.viewContent=this.view.view.view();this._useCSS3=AC.Detector.isCSSAvailable("transform")&&AC.Detector.isCSSAvailable("transition");
this._isiOS=AC.Detector.isiPad()||AC.Detector.isMobile();this._use3D=AC.Detector.supportsThreeD()&&!(this._isiOS&&!!this.view.options.no3DForiOS);
if(this.view&&this.viewContent){this._setupSections();if(!this.view._noCarousel){this._boundStart=this.start.bindAsEventListener(this);
this.viewContent.observe("ScaleController:Start",this._boundStart);this._boundStop=this.stop.bindAsEventListener(this);
this.viewContent.observe("ScaleController:Stop",this._boundStop);this._boundInterval=this.set.bindAsEventListener(this);
this.viewContent.observe("ScaleController:Set",this._boundInterval)}else{if(!this._use3D){this.viewContent.addClassName("no3d")
}this.viewContent.addClassName("noCarousel")}}},_setupSections:function(){this.sections=this.view.sections._object;
this.sectionsContent=[];this.view.orderedSections.each(this._setupSection.bind(this))
},_setupSection:function(d){var c=this.sections[d];var b=c===this.view.currentSection?true:false;
c.dimensions=c.content.getDimensions();c.dimensions.fontSize=parseFloat(c.content.getStyle("font-size"));
this.sectionsContent.push(c.content);if(b){this.set(c.content,this.options.scaleMax)
}else{this.set(c.content,this.options.scaleMin)}var a=c.content.down("a.carouselMovieLink");
if(typeof a!=="undefined"){if(!this.view.videoController){this.view.videoController=new AC.ViewMaster.CarouselViewer.VideoController(this.view)
}this.view.videoController.addSection(c,a)}if(this.view.options.shouldGotoSectionOnClick&&!this.view._noCarousel){c._boundGoToSectionOnClick=this._goToSectionOnClick.bindAsEventListener(c);
c.content.observe("click",c._boundGoToSectionOnClick)}},set:function(d,c,a){if(!!this.view._noCarousel){return false
}if(!a){a=false}if(this._useCSS3){if(!a){d.setVendorPrefixStyle("transition",".01s -webkit-transform linear")
}if(this._use3D){d.setVendorPrefixStyle("transform","scale3d("+c+","+c+","+c+")")
}else{d.setVendorPrefixStyle("transform","scale("+c+")")}}else{var b=this._getProps(d,c,(c===this.options.scaleMax));
d.setStyle("width: "+b.width+"px;height: "+b.height+"px;padding-left: "+b["padding-left"]+"px;padding-right: "+b["padding-left"]+"px;padding-top: "+b["padding-top"]+"px;font-size: "+b["font-size"]+"px;");
d.setAttribute("scale",c)}},_goToSectionOnClick:function(a){if(this.viewMaster.currentSection!==this&&!("videoController" in this.viewMaster&&!!this.viewMaster.videoController.videoIsPlaying)){this.viewMaster.show(this);
this.viewMaster._currentTrigger=this.content;this.viewMaster.view.view().fire("AC.ViewMaster.Slideshow:stop")
}},_getProps:function(b,d,c){if(!c){c=false}var e=b.id.replace("MASKED-","");var a={width:Math.round(this.sections[e].dimensions.width*d),height:Math.round(this.sections[e].dimensions.height*d),"padding-left":Math.round(c?0:(this.sections[e].dimensions.width-(this.sections[e].dimensions.width*d))/2),"padding-top":Math.round(c?0:(this.sections[e].dimensions.height-(this.sections[e].dimensions.height*d))/2),"font-size":Math.round(this.sections[e].dimensions.fontSize*d*1000)/1000};
return a},_getDistanceBetween:function(c,a){var d=this.sectionsContent[a].offsetLeft,b=this.sectionsContent[c].offsetLeft;
return Math.abs(d-b)},start:function(b){this._data=b.memo;var d=0;var a=this._getDistanceBetween(this._data.outgoingIndex,this._data.incomingIndex);
var c=this;var f=function(h){var l=c._getDistanceBetween(h+g,h);var j=l/a;var k=j*c.view.options.animationDuration;
c.scaleInOut.delay(d,c,h,g,k);d+=k};if(this._data.outgoingIndex<this._data.incomingIndex){var g=-1;
for(var e=this._data.outgoingIndex-g;e<=this._data.incomingIndex;e+=1){f(e)}}else{var g=1;
for(var e=this._data.outgoingIndex-g;e>=this._data.incomingIndex;e-=1){f(e)}}},scaleInOut:function(a,b,d,c){a._animate(a.sectionsContent[b+(1*d)],a.options.scaleMin,c,0);
a._animate(a.sectionsContent[b],a.options.scaleMax,c,0)},stop:function(){delete this._data
},_animate:function(c,b,d){if(this._useCSS3){c.setVendorPrefixStyle("transition",d+"s -webkit-transform linear");
if(this._use3D){c.setVendorPrefixStyle("transform","scale3d("+b+","+b+","+b+")")
}else{c.setVendorPrefixStyle("transform","scale("+b+")")}}else{var a=this._getProps(c,b,(b===this.options.scaleMax));
new Effect.Morph(c,{style:"width: "+a.width+"px;height: "+a.height+"px;padding-left: "+a["padding-left"]+"px;padding-right: "+a["padding-left"]+"px;padding-top: "+a["padding-top"]+"px;font-size: "+a["font-size"]+"px;",duration:d});
c.setAttribute("scale",b)}}});
