var Zoomerlay=Class.create();Zoomerlay.options={minWidth:980,minHeight:600,outerSpacingX:0.1,outerSpacingY:0.1,maskSizeDiffX:2,maskSizeDiffY:26,shouldNotZoom:false};
Object.extend(Zoomerlay.prototype,{initialize:function(g,e,h,f){Zoomerlay.instances[e]=this;
this.options=Object.extend(Object.clone(Zoomerlay.options),f);this.viewer=new AC.ViewMaster.Viewer(null,h,g,{parentSectionId:e,parentTriggerClassName:"OverlayPanel",silentTriggers:true,shouldAnimateContentChange:false});
this.viewer.setDelegate({willShow:this.willShow.bind(this),didShow:this.didShow.bind(this)});
this.bindResize=this.resize.bind(this);this.bindMouseMove=this.onMouseMove.bind(this);
this.bindMouseDown=this.onMouseDown.bind(this);this.bindClick=this.onClick.bind(this)
},willShowOverlay:function(b){if(!this.initialized){this.initialized=true;this.overlay=$(b.event_data.data.incomingView.content);
this.heading=this.overlay.down("h2");this.mask=this.overlay.down(".mask");this.footer=this.overlay.down(".footer");
if(this.options.shouldNotZoom){this.overlay.addClassName("no-zoom")}}this.setMaskSize();
Event.observe((document.onresize?document:window),"resize",this.bindResize)},didShowOverlay:function(b){if(this.resetOnDidShowOverlay){this.didShow()
}this.resetOnDidShowOverlay=false;if(this.footer){this.footer.style.bottom="0px"
}},beforeCloseOverlay:function(b){Event.stopObserving((document.onresize?document:window),"resize",this.bindResize);
$(document.body).removeClassName("dragging");if(this.draggable){this.draggable.destroy()
}this.resetOnDidShowOverlay=true;if(this.caption){this.caption.remove()}},willShow:function(d,f,e){if(this.draggable){this.draggable.destroy()
}if(this.caption){this.caption.remove()}this.overlay.removeClassName("zoomed");
Event.stopObserving(this.mask,"mousemove",this.bindMouseMove);this.element=$(e.content);
if(!this.element.z){this.element.z={width:this.element.getAttribute("width"),height:this.element.getAttribute("height"),caption:this.element.getAttribute("title"),zoomed:false};
this.element.setAttribute("title","")}},didShow:function(d,f,e){if(this.element.z.zoomed){this.overlay.removeClassName("zoomed");
this.element.z.zoomed=false;if(this.footer){this.footer.show()}if(this.draggable){this.draggable.destroy()
}}if(this.element.z.caption){this.caption=new Element("p",{"class":"caption"}).update(this.element.z.caption);
this.element.insert({after:this.caption})}else{this.caption=null}this.setContentSizeAndBounds();
Event.observe(this.element,"mousedown",this.bindMouseDown);Event.observe(this.element,"click",this.bindClick)
},setMaskSize:function(){var f=window.innerWidth||(window.document.documentElement.clientWidth||window.document.body.clientWidth),h=window.innerHeight||(window.document.documentElement.clientHeight||window.document.body.clientHeight);
if(f<this.options.minWidth){f=this.options.minWidth}if(h<this.options.minHeight){h=this.options.minHeight
}this.overlayWidth=f-(this.options.outerSpacingX*f);this.overlayHeight=h-(this.options.outerSpacingY*h);
this.maskWidth=this.overlayWidth-this.options.maskSizeDiffX;this.maskHeight=this.overlayHeight-this.options.maskSizeDiffY;
if(this.options.contentWidth&&this.options.contentHeight){var i=20,j=20+(this.options.caption?22:0)+(this.options.thumbs?72:0);
var g=this.getShrunkContentDimensions(this.options.contentWidth,this.options.contentHeight,this.maskWidth-i,this.maskHeight-j);
this.maskWidth=g[0]+i;this.maskHeight=g[1]+j;this.overlayWidth=this.maskWidth+this.options.maskSizeDiffX;
this.overlayHeight=this.maskHeight+this.options.maskSizeDiffY}this.overlay.style.width=this.overlayWidth+"px";
this.overlay.style.height=this.overlayHeight+"px";this.mask.style.width=this.maskWidth+"px";
this.mask.style.height=this.maskHeight+"px"},getShrunkContentDimensions:function(h,f,i,j){if(h>i){var g=i/h;
h*=g;f*=g}if(f>j){var g=j/f;h*=g;f*=g}return[h,f]},setContentSizeAndBounds:function(C,q){var s=this.element.z.width,w=this.element.z.height;
if(!this.element.z.zoomed){this.footerHeight=(this.footer?this.footer.getHeight():0)+(this.caption?(this.caption.getHeight()+4):0);
var v=this.maskWidth-20,p=this.maskHeight-20-this.footerHeight;if(s>v){var u=v/s;
s*=u;w*=u}if(w>p){var u=p/w;s*=u;w*=u}if(this.caption){this.caption.style.top=(p+18)+"px"
}}var D=s,r=w;if(this.maskWidth<D){this.xMin=0;this.xMax=this.maskWidth-D}else{var A=(this.maskWidth-D)/2;
this.xMin=A;this.xMax=this.maskWidth-D-A}if(!this.element.z.zoomed&&this.footerHeight){this.maskHeight-=this.footerHeight
}if(this.maskHeight<r){this.yMin=0;this.yMax=this.maskHeight-r}else{var A=(this.maskHeight-r)/2;
this.yMin=A;this.yMax=this.maskHeight-r-A}if(!this.element.z.zoomed&&this.footerHeight){this.maskHeight+=this.footerHeight
}if(this.caption){this.caption.style.width=(this.maskWidth-20)+"px"}if(C){var y=this.xMin,B=this.yMin;
if(q){var z=this.element.cumulativeOffset();y-=(s*((q.pageX-z.left)/this.element.getWidth()))-(this.maskWidth/2);
if(y>this.xMin){y=this.xMin}else{if(y<this.xMax){y=this.xMax}}B-=(w*((q.pageY-z.top)/this.element.getHeight()))-(this.maskHeight/2);
if(B>this.yMin){B=this.yMin}else{if(B<this.yMax){B=this.yMax}}}var x=(100*s)/this.element.getWidth();
new Effect.Parallel([new Effect.Move(this.element,{sync:true,x:y,y:B,mode:"absolute"}),new Effect.Scale(this.element,x,{sync:true})],{duration:0.3})
}else{this.element.setStyle({width:s+"px",height:w+"px",left:this.xMin+"px",top:this.yMin+"px"})
}},resize:function(){this.setMaskSize();this.setContentSizeAndBounds();this.resizeOverlay(this.overlayWidth,this.overlayHeight)
},resizeOverlay:function(c,d){AC.OverlayPanel.overlay.overlay.setStyle({width:c+"px",height:d+"px"});
AC.OverlayPanel.overlay.defaultWidth=c;AC.OverlayPanel.overlay.defaultHeight=d;
AC.OverlayPanel.overlay.positionOverlay()},css:function(e,f){if(f){var d={};d[e]=f+"px";
this.element.setStyle(d)}else{return(val=this.element.getStyle(e))?parseInt(val):0
}},onMouseMove:function(b){if(this.footer){if((b.pageY-this.mask.cumulativeOffset().top)>(this.maskHeight-40)){if(!this.dragging&&!this.footerVisible){this.footerVisible=true;
if(this.footerEffect){this.footerEffect.cancel()}this.footerEffect=new Effect.Morph(this.footer,{style:{bottom:"0px"},duration:0.2})
}}else{if(this.footerVisible){this.footerVisible=false;if(this.footerEffect){this.footerEffect.cancel()
}this.footerEffect=new Effect.Morph(this.footer,{style:{bottom:-this.footerHeight+"px"},duration:0.2})
}}}this.overlay.addClassName("grabcursor");if(this.mouseMoveTimeout){clearTimeout(this.mouseMoveTimeout)
}if(!this.footer||!this.footerVisible){this.mouseMoveTimeout=setTimeout(this.onMousePause.bind(this),2000)
}},onMousePause:function(){this.overlay.removeClassName("grabcursor")},onMouseDown:function(b){this.mouseEvent=b
},onClick:function(b){if(this.mouseEvent&&b.pageX==this.mouseEvent.pageX&&b.pageY==this.mouseEvent.pageY){if(!this.element.z.zoomed){this.zoomIn(b)
}else{this.zoomOut(b)}}},zoomIn:function(d){if(!this.options.shouldNotZoom){this.element.z.zoomed=true;
this.setContentSizeAndBounds(true,d);var c=[];if(this.caption){c.push(new Effect.Morph(this.caption,{style:{marginTop:this.footerHeight+"px"},sync:true}))
}if(this.footer){c.push(new Effect.Morph(this.footer,{style:{bottom:-this.footerHeight+"px"},sync:true}))
}if(c.length>0){new Effect.Parallel(c,{duration:0.2,afterFinish:function(){if(this.caption){this.caption.hide()
}this.overlay.addClassName("zoomed")}.bind(this)})}this.draggable=new Draggable(this.element,{starteffect:null,reverteffect:null,endeffect:null,onStart:this.onDragStart.bind(this),onDrag:this.onDrag.bind(this),change:this.change.bind(this),onEnd:this.onDragEnd.bind(this)});
Event.observe(this.mask,"mousemove",this.bindMouseMove);AC.Tracking.trackClick({prop3:AC.Tracking.pageName()+" - "+this.element.id.replace("MASKED-","")+" - zoom in"},this,"o",AC.Tracking.pageName()+" - "+this.element.id.replace("MASKED-","")+" - zoom in")
}},zoomOut:function(d){this.draggable.destroy();this.overlay.removeClassName("zoomed");
this.element.z.zoomed=false;this.setContentSizeAndBounds(true);var c=[];if(this.caption){this.caption.show();
c.push(new Effect.Morph(this.caption,{style:{marginTop:"0px"},sync:true}))}if(this.footer){c.push(new Effect.Morph(this.footer,{style:{bottom:"0px"},sync:true}))
}if(c.length>0){new Effect.Parallel(c,{duration:0.2,delay:0.1})}Event.stopObserving(this.mask,"mousemove",this.bindMouseMove);
AC.Tracking.trackClick({prop3:AC.Tracking.pageName()+" - "+this.element.id.replace("MASKED-","")+" - zoom out"},this,"o",AC.Tracking.pageName()+" - "+this.element.id.replace("MASKED-","")+" - zoom out")
},onDragStart:function(d,c){$(document.body).addClassName("dragging");this.dragging=true;
if(this.effect&&this.effect.state=="running"){this.effect.cancel()}this.interval=setInterval(this.updateHistory.bind(this),30);
this.history=$A();AC.Tracking.trackClick({prop3:AC.Tracking.pageName()+" - "+this.element.id.replace("MASKED-","")+" - dragging"},this,"o",AC.Tracking.pageName()+" - "+this.element.id.replace("MASKED-","")+" - dragging")
},onDrag:function(d,c){this.cursor=[c.clientX,c.clientY]},updateHistory:function(){if(this.history.length>2){this.history.pop()
}this.history.unshift(this.cursor)},change:function(e){var f=this.css("left"),d=this.css("top");
if(f>this.xMin){this.css("left",f+(this.xMin-f)/2)}else{if(f<this.xMax){this.css("left",f+((this.xMax-f)/2))
}}if(d>this.yMin){this.css("top",d+(this.yMin-d)/2)}else{if(d<this.yMax){this.css("top",d+((this.yMax-d)/2))
}}},onDragEnd:function(f,e){$(document.body).removeClassName("dragging");this.dragging=false;
var g=this.css("left"),h=this.css("top");if(this.history.length>=2){g-=(parseInt(this.history.last()[0]-this.history.first()[0])/this.history.length)*10,h-=(parseInt(this.history.last()[1]-this.history.first()[1])/this.history.length)*10
}xBand=g-(g>this.xMin?this.xMin:(g<this.xMax?this.xMax:g)),yBand=h-(h>this.yMin?this.yMin:(h<this.yMax?this.yMax:h));
this.effect=new Zoomerlay.Move(this.element,{duration:0.5,x:g,y:h,xBand:xBand,yBand:yBand});
this.history=null;clearInterval(this.interval)}});Zoomerlay.instances={};Zoomerlay.Dispatch=Class.create({initialize:function(){this.listenForEvent(AC.ViewMaster,"ViewMasterWillShowNotification",false,this.willShow);
this.listenForEvent(AC.ViewMaster,"ViewMasterDidShowNotification",false,this.didShow);
this.listenForEvent(AC.OverlayPanel.overlay,"afterPop",false,this.afterPop);this.listenForEvent(AC.OverlayPanel.overlay,"beforeClose",false,this.beforeClose);
this.listenForEvent(AC.OverlayPanel.overlay,"afterClose",false,this.afterClose)
},isZoomerlay:function(b){return(b.event_data.data.sender.overlayId=="OverlayPanel"&&b.event_data.data.incomingView&&Zoomerlay.instances[b.event_data.data.incomingView.id])
},willShow:function(b){if(!this.isZoomerlay(b)){return}this.currentInstance=Zoomerlay.instances[b.event_data.data.incomingView.id];
this.currentInstance.willShowOverlay(b);AC.OverlayPanel.overlay.overlay.addClassName("zoomerlay");
AC.OverlayPanel.overlay.setOverlayShadowImageSrc("/global/elements/zoomerlay/zoomerlay_bg.png")
},didShow:function(b){if(!this.isZoomerlay(b)){return}this.currentInstance.didShowOverlay(b)
},afterPop:function(b){Event.stopObserving((document.onresize?document:window),"resize",AC.OverlayPanel.overlay.bindPositionOverlay)
},beforeClose:function(b){if(this.currentInstance){this.currentInstance.beforeCloseOverlay(b)
}},afterClose:function(b){AC.OverlayPanel.overlay.overlay.removeClassName("zoomerlay");
AC.OverlayPanel.overlay.setOverlayShadowImageSrc(Zoomerlay.defaultOverlayShadowSrc)
}});Object.extend(Zoomerlay.Dispatch.prototype,Event.Listener);Zoomerlay.Move=Class.create(Effect.Base,{initialize:function(c,d){this.element=$(c);
if(!this.element){throw (Effect._elementDoesNotExistError)}var d=Object.extend({x:0,y:0,xBand:0,yBand:0,mode:"absolute",transition:Effect.Transitions.linear},arguments[1]||{});
this.start(d)},setup:function(){this.element.makePositioned();this.originalLeft=(l=this.element.getStyle("left"))?parseFloat(l):0;
this.originalTop=(t=this.element.getStyle("top"))?parseFloat(t):0;if(this.options.mode=="absolute"){this.options.x=this.options.x-this.originalLeft;
this.options.y=this.options.y-this.originalTop}},update:function(e){e=Effect.Transitions.Expo.easeOut(e);
var g=(e*this.fromToDelta)+this.options.from,f=e*this.options.xBand,h=e*this.options.yBand;
this.element.setStyle({left:(this.options.x*g-f+this.originalLeft).round()+"px",top:(this.options.y*g-h+this.originalTop).round()+"px"})
}});Event.onDOMReady(function(){Zoomerlay.defaultOverlayShadowSrc=AC.OverlayPanel.overlay._overlayShadowSrc;
AC.OverlayScreen.opacity=0.5;new Zoomerlay.Dispatch()});
