var tv_swap=Class.create({defaultOptions:{shouldAnimateZoom:false,shouldAnimateCrossfade:false,shouldCrossfadeBlurs:false,useSlideShow:false,slideShowDelay:5000},defaultSwapViewOptions:{silentTriggers:true,useKeyboardNav:true,discontinuousPreviousNext:true},initialize:function(d,b,e,c,a){if(!c){c={}
}this.options=Object.clone(this.defaultOptions);Object.extend(this.options,c);if(!a){a={}
}this.swapViewOptions=Object.clone(this.defaultSwapViewOptions);Object.extend(this.swapViewOptions,a);
if(this.options.shouldAnimateZoom){this.animate=this.animateZoom}else{if(this.options.shouldAnimateCrossfade){this.animate=this.animateCrossfade
}}this.caption=$(b+"-caption");if(this.caption===undefined){this.caption=false}this.container=$(b);
this.view=new AC.ViewMaster.Viewer(d,b,e,this.swapViewOptions);this.view.setDelegate(this);
if(AC.Detector.isiPad()||AC.Detector.isiPhone()){document.body.addClassName("iOS")
}this.blurs=$$("."+b+"-blur");if(this.blurs[0]){this.blurContainer=this.blurs[0].up();
this.blursIncrement=this.blurs[0].getWidth()+parseFloat(this.blurs[0].getStyle("margin-right"));
this.blurCurrentLeft=0;if(this.options.shouldCrossfadeBlurs){this.setUpBlurs()}}else{this.blurs=false
}if(this.options.useSlideShow){this.slideshow=new AC.ViewMaster.Slideshow(this.view,"slideshow-link",{delay:this.options.slideShowDelay,autoplay:true,stopOnContentTriggerClick:true})
}},getBlurLeftOffset:function(a){return(this.getBlurIndex(a.id)*this.blursIncrement)*-1
},getBlurIndex:function(c,b){c=c.replace("MASKED-","");var a=this.view.orderedSections.indexOf(c);
if(!b){return this.view.orderedSections.indexOf(c)}else{return(a+b>=0)?(a+b<this.view.orderedSections.length)?a+b:0:this.view.orderedSections.length-1
}},setUpBlurs:function(){this.blurContainers=[];this.oldBlurs=[];var a=new Element("div",{"class":"screen-blurs"});
this.blurContainers.push(new Element("div",{"class":"screen-blur"}));this.blurContainers.push(new Element("div",{"class":"screen-blur"}));
a.insert(this.blurContainers[0]);a.insert(this.blurContainers[1]);this.setBlur(this.view.currentSection.content,-1);
this.setBlur(this.view.currentSection.content,1);this.container.up(".tv-swap").insert({top:a})
},setBlur:function(e,h,g){if(!g){g=0}if(this.blurContainers&&this.blurContainers.length>1){var d=(h===1)?1:0,f=this.blurs[this.getBlurIndex(e.id,h)].cloneNode(true),b=this.oldBlurs[d],c=this.blurContainers[d];
f.setStyle("position: absolute");if(b){var a=function(){b.remove()};c.insert(f);
this.animateCrossfade(false,b,f,a,g,1,b,0,0)}else{c.update(f)}this.oldBlurs[d]=f
}},getCaption:function(a){var b=a.content.down("img");if(b!==undefined&&b.alt!==undefined&&b.alt!==""){return b.alt
}else{if(a.content.title!==undefined&&a.content.title!==""){return a.content.title
}else{return""}}},hideCaption:function(){this.caption.setOpacity(0.0001)},showCaption:function(a){this.caption.update(this.getCaption(a));
this.caption.setOpacity(1)},animateZoom:function(e,h,c,b,j,d,f,a,i){c.setOpacity(1);
c.style.zIndex=10;h.style.zIndex=11;if(AC.Detector.isCSSAvailable("animation")){if(AC.Detector.supportsThreeD()){h.addClassName("fadethrough3d")
}else{h.addClassName("fadethrough")}var g=function(k){if(k.target==h){h.removeVendorEventListener("animationEnd",g,false);
h.removeClassName("fadethrough3d");h.removeClassName("fadethrough");if(b){b()}}};
h.addVendorEventListener("animationEnd",g,false)}else{return this.animateCrossfade(e,h,c,b,j,d,f,a,i)
}},animateCrossfade:function(f,i,d,c,l,e,g,b,k){d.setOpacity(1);var j=(f)?f.view.view():null;
if(j){j.style.position="relative"}if(i){i.style.position="absolute"}if(d){d.style.position="absolute"
}d.style.zIndex=10;i.style.zIndex=11;var a=function(){if(j){j.style.position=""
}if(i){i.style.position=""}if(d){d.style.position=""}if(c){c()}};if(AC.Detector.isCSSAvailable("transition")){var h=function(m){if(m.target==i&&!!m.propertyName.match("opacity")){i.removeVendorEventListener("transitionEnd",h,false);
i.removeClassName("outgoing");a()}};i.addVendorEventListener("transitionEnd",h,false);
i.addClassName("outgoing");i.setVendorPrefixStyle("transition",e+"s opacity linear");
(function(){i.setOpacity(0.0001)}).delay(0.001)}else{return new Effect.Opacity(i,{from:1,to:0,duration:e,afterFinish:a,queue:{scope:l}})
}},willShow:function(a,c,b){if(this.caption){this.hideCaption()}},didShow:function(a,c,b){if(this.caption){this.showCaption(b)
}},willAnimate:function(e,g,c,b,j,d){var i=e.view.view(),a=i.offsetLeft||0,h=-c.offsetLeft||0;
if(this.blurs){var f=this.getBlurLeftOffset(c)}c.setOpacity(1);if(this.blurs){if(this.options.shouldCrossfadeBlurs){this.setBlur(c,-1,j);
this.setBlur(c,1,j)}else{this.animateSlide(e,g,c,false,j,d,this.blurContainer,this.blurCurrentLeft,f);
this.blurCurrentLeft=f}}return this.animate(e,g,c,b,j,d,i,a,h)}});
