var CL=CL||{};CL.Views.FeaturedGallerySlide=CL.Views.GallerySlide.extend({initialize:function(){var view=this;this.state=this.options.state;this.options.animationDuration=600;this.$pictureFill=$("span.picturefill",this.$el);this.$pictureFill.on("pictureChanged",function(){view.processImage();});if($(".video-container").length){this.setupVideo();}},processImage:function(){var view=this,$image=$("img",this.$pictureFill),imageHeight=$image.attr("height"),imageWidth=$image.attr("width"),imageRatio=imageWidth/imageHeight;this.maxRatio=2.21;this.minRatio=4/3;if(imageRatio>this.maxRatio){this.ratio=this.maxRatio;}else if(imageRatioimageRatio){$image.css({"left":(((imageRatio/this.ratio)-1)/-2)*100+"%","top":0,"width":"auto","height":"100%"});}else{$image.css({"top":(((this.ratio/imageRatio)-1)/-2)*100+"%","left":0,"width":"100%","height":"auto"});} this.trigger("imageProcessed");},enter:function(direction){var view=this,before={"z-index":1,},after={},afterAnimate;if(direction=="next"){_.extend(before,{"left":"100%"});_.extend(after,{"left":0});}else if(direction=="prev"){_.extend(before,{"left":"-100%"});_.extend(after,{"left":0});}else{_.extend(before,{"opacity":0});_.extend(after,{"opacity":1});} this.$el.show().css(before);this.reportSlideHeight();afterAnimate=function(){view.reportSlideHeight();} if(CL.vars.isFirefox||CL.vars.isIE9){this.$el.stop().animate(after,this.options.animationDuration,afterAnimate);}else{this.$el.transitionStop().transition(after,this.options.animationDuration,afterAnimate);} if(CL.utilities.isTouch()&&this.hasVideo){this.enterVideo();}},exit:function(direction,success){var view=this,before={"z-index":0},after={};if(direction=="next"){_.extend(after,{"left":"100%"});}else if(direction=="prev"){_.extend(after,{"left":"-100%"});}else{_.extend(after,{"opacity":0});} if(CL.vars.isFirefox||CL.vars.isIE9){this.$el.css(before).show().stop().delay(1).animate(after,this.options.animationDuration,function(){view.$el.hide();});}else{this.$el.css(before).show().transitionStop().delay(1).transition(after,this.options.animationDuration,function(){view.$el.hide();});} if(this.videoOpen){this.exitVideo();} success&&success();},setupVideo:function(){var view=this;this.template=_.template($("#video-iframe-template").html());this.$videoContainer=$(".video-container",this.$el);this.$videoButton=$("a.play",this.$videoContainer);this.$videoWrapper=$(".wrapper",this.$videoContainer);if(!CL.utilities.isTouch()){this.$videoButton.on("click",function(ev){ev.preventDefault();if(!view.videoOpen){view.enterVideo();}});} this.hasVideo=true;$(window).on("slideshowVideoEnter.view-"+this.cid,function(){if(view.videoOpen&&!CL.utilities.isTouch()){view.exitVideo();}});if(CL.vars.isAndroid){$(document).on("webkitfullscreenchange",function(){var exit=!document.webkitFullscreenElement;if(exit){view.enterVideo();}});}},enterVideo:function(){var view=this,videoData=_.extend(this.$videoContainer.data(),{"autoplay":!CL.utilities.isTouch()});this.$videoWrapper.html(this.template(videoData));this.$videoWrapper.css({"opacity":0}).show().transition({"opacity":1});if(!CL.vars.isIE11){this.$videoWrapper.fitVids();}else{$("iframe",this.$videoWrapper).css({"height":"100%","width":"100%"});} this.$videoButton.fadeOut();$(window).trigger("slideshowVideoEnter");this.videoOpen=true;},exitVideo:function(){if(!CL.utilities.isTouch()){this.$videoWrapper.fadeOut();this.$videoButton.fadeIn();} this.$videoWrapper.empty();this.videoOpen=false;},reportSlideHeight:function(){var slideHeight=(100/this.ratio)+"%";this.state.set("activeSlideHeight",slideHeight);},tearDown:function(){if(this.videoOpen){this.exitVideo();} CL.Views.GallerySlide.prototype.tearDown.call(this);}});CL.Views.FeaturedGalleryCaption=CL.Views.GallerySubobjectItem.extend({initialize:function(){this.state=this.options.state;this.options.animationDuration=650;this.$inner=$(".inner",this.$el);},enter:function(direction){var before={"x":"0%"},after={"x":"0%"},captionBefore={"opacity":0},captionAfter={"opacity":1},captionDuration,captionDelay;if(direction=="next"){_.extend(before,{"x":"100%"});captionDuration=this.options.animationDuration/4;}else if(direction=="prev"){_.extend(before,{"x":"-100%"});captionDuration=this.options.animationDuration/2;} this.$el.css(before).show().transitionStop().transition(after,this.options.animationDuration);captionDelay=(captionDuration0?this.options.animationDuration-captionDuration:0;_.extend(captionAfter,{"delay":captionDelay});this.$inner.css(captionBefore).show().transitionStop().transition(captionAfter,captionDuration,function(){if(direction){CL.utilities.unlockWrapper();}});},exit:function(direction,success){var view=this,after={},captionAfter={},captionDuration;CL.utilities.lockWrapper();if(direction=="next"){_.extend(after,{"x":"100%"});captionDuration=this.options.animationDuration/4;}else if(direction=="prev"){_.extend(after,{"x":"-100%"});captionDuration=this.options.animationDuration/2;} this.$inner.transitionStop().transition(captionAfter,captionDuration,function(){$(this).hide();});this.$el.transitionStop().transition(after,this.options.animationDuration,function(){$(this).hide();});success&&success();}});CL.Views.FeaturedGalleryCaptions=CL.Views.GallerySubobject.extend({subObj:CL.Views.FeaturedGalleryCaption,waitForStateReady:true,enter:function(){this.$el.css({"opacity":0,"y":"-24px"}).show().transition({"opacity":1,"y":0},this.options.animationDuration);},goToCurrentIndex:function(){this.goToIndex(this.state.get("index"),this.state.get("direction"));},goToIndex:function(index,direction){var newObj=this.objects[index],oldObjDirection=direction&&(direction=="backward"?"next":"prev"),newObjDirection=direction&&(direction=="backward"?"prev":"next");if(newObj){if(this.activeObj){this.activeObj.exit(oldObjDirection,function(){newObj.enter(newObjDirection);});}else{newObj.enter(newObjDirection);} this.activeObj=newObj;}}});CL.Views.FeaturedGallerySlides=CL.Views.GallerySlides.extend({subObj:CL.Views.FeaturedGallerySlide,listenForSlideHeight:true});CL.Views.FeaturedGalleryControls=CL.Views.GalleryControls.extend({enter:function(){if(this.objects.length>1){this.$el.css({"opacity":0,"y":"-24px"}).show().transition({"opacity":1,"y":0},this.options.animationDuration);}}});CL.Views.FeaturedGallery=CL.Views.Gallery.extend({slidesObj:CL.Views.FeaturedGallerySlides,controlsObj:CL.Views.FeaturedGalleryControls,waitForImageReady:true,swipeEnabled:true,beforeSubobjects:function(){var view=this;this.state.on("change:activeSlideHeight",function(){view.setHeight();});},setHeight:function(){if(this.state.get("state")=="ready"){var resize=setInterval(function(){$(window).trigger("resize");},5);this.$el.transitionStop().transition({"padding-top":this.state.get("activeSlideHeight")},500,function(){clearInterval(resize);});}else{this.$el.css({"padding-top":this.state.get("activeSlideHeight")});} $(window).trigger("resize");},afterInit:function(){if($("ul.captions").length){this.captions=new CL.Views.FeaturedGalleryCaptions({"el":$("ul.captions",this.$el),"state":this.state,});}}});