Prototype.require("jojoPopupEffect.js");Popup=Class.create(PopupEffect,{onResizeHandler:null,scrollX:0,scrollY:0,fadeBackgroundElement:null,oldElement:null,oldParentElement:null,initialize:function($super,B,A){$super(B,A);this.fadeBackgroundElement=null;this.setOptions({fadeBackground:false,parallelBackgroundEffect:true,zIndex:100,shadow:false,shadowClass:"Shadow",onResize:null});this.setOptions(A);A=A||{};this.options.fadeBackgroundOption=Object.extend({backgroundColor:"#888"},A.fadeBackgroundOption||{})},show:function($super){if(this.element&&!this.element.visible()){if(this.options.fadeBackground&&this.fadeBackgroundElement==null){Prototype.require("jojoFullscreenElement.js");var G=this.options.fadeBackgroundOption;G.zIndex=this.options.zIndex-2;if(!this.options.parallelBackgroundEffect){G.onShow=this.show.bind(this)}this.fadeBackgroundElement=new FullScreenElement("",G);this.fadeBackgroundElement.show();if(!this.options.parallelBackgroundEffect){return}}if(this.options.shadow){this.oldParentElement=this.element.up();this.oldElement=this.element;this.element=new Element("TABLE",{cellPadding:0,cellSpacing:0,border:0});this.element.hide();this.element.addClassName(this.options.shadowClass);var A=new Element("TBODY");var H=new Element("TR");A.appendChild(H);H.appendChild(new Element("TH",{"class":"TopLeftShadow"}));H.appendChild(new Element("TH",{"class":"TopShadow"}));H.appendChild(new Element("TH",{"class":"TopRightShadow"}));var H=new Element("TR");A.appendChild(H);H.appendChild(new Element("TH",{"class":"LeftShadow"}));H.appendChild(new Element("TD"));H.appendChild(new Element("TH",{"class":"RightShadow"}));var H=new Element("TR");A.appendChild(H);H.appendChild(new Element("TH",{"class":"BottomLeftShadow"}));H.appendChild(new Element("TH",{"class":"BottomShadow"}));H.appendChild(new Element("TH",{"class":"BottomRightShadow"}));this.element.appendChild(A);this.element.down("TD").appendChild(this.oldElement);if(Prototype.Browser.Gecko){var D=new Element("DIV");D.hide();D.appendChild(this.element);this.element.show();this.element=D}this.oldElement.show();this.oldParentElement.appendChild(this.element)}dimension=Prototype.Browser.getDimensions();this.scrollX=dimension.offsetX;this.scrollY=dimension.offsetY;this.element.setStyle({visibility:"hidden",position:"absolute"});this.element.show();var I=this.element.getDimensions();this.element.hide();this.element.setStyle({visibility:"visible"});var C=parseInt(((dimension.clientWidth-I.width)/2)+dimension.offsetX);var B=parseInt(((dimension.clientHeight-I.height)/2)+dimension.offsetY);var F;var E;if(I.height>dimension.clientHeight){if(I.height>=dimension.height){E=0}else{E=[[0,B].max(),dimension.height-I.height].min()}}else{E=B}if(I.width>dimension.clientWidth){if(I.width>=dimension.width){F=0}else{F=[[0,C].max(),dimension.width-I.width].min()}}else{F=C}this.element.setStyle({top:E+"px",left:F+"px",zIndex:this.options.zIndex});this.onResizeHandler=this.onResize.bindAsEventListener(this);this.onScrollHandler=this.onScroll.bindAsEventListener(this);this.element.observe("resize",this.onResizeHandler);Event.observe(window,"scroll",this.onScrollHandler);$super()}},onBrowserResize:function(){var A=Prototype.Browser.getDimensions();this.scrollX=A.offsetX;this.scrollY=A.offsetY;this.onResize();if(this.fadeBackgroundElement!=null){this.fadeBackgroundElement.onBrowserResize()}},onScroll:function(){this.onResize()},onResize:function(){var E=Prototype.Browser.getDimensions();var B=this.element.getDimensions();var D=parseInt(((E.clientWidth-B.width)/2)+E.offsetX);var C=parseInt(((E.clientHeight-B.height)/2)+E.offsetY);var A;var F;if(B.height>E.clientHeight){if(B.height>=E.height){F=0}else{scrollOffsetY=parseInt((B.height-E.clientHeight)/2);direction=1;if(E.offsetY>=this.scrollY){direction=-1}if(this.scrollY<scrollOffsetY){this.scrollY=scrollOffsetY}else{if(this.scrollY>E.height-E.clientHeight-scrollOffsetY){this.scrollY=E.height-E.clientHeight-scrollOffsetY}}offset=parseInt(Math.abs(this.scrollY-E.offsetY));F=C+[scrollOffsetY,offset].min()*direction;if(scrollOffsetY<=offset){this.scrollY=E.offsetY+scrollOffsetY*direction}}}else{F=C}if(B.width>E.clientWidth){if(B.width>=E.width){A=0}else{scrollOffsetX=parseInt((B.width-E.clientWidth)/2);direction=1;if(this.scrollX<scrollOffsetX){this.scrollX=scrollOffsetX}else{if(this.scrollX>E.width-E.clientWidth-scrollOffsetX){this.scrollX=E.width-E.clientWidth-scrollOffsetX}}if(E.offsetX>=this.scrollX){direction=-1}offset=parseInt(Math.abs(this.scrollX-E.offsetX));A=D+[scrollOffsetX,offset].min()*direction;if(scrollOffsetX<=offset){this.scrollX=dimensions.offsetX+scrollOffsetX*direction}}}else{A=D}this.element.setStyle({top:F+"px",left:A+"px"});if(this.oOverlappingFix!=null){this.oOverlappingFix.update(this.element)}if(this.options.onResize){this.options.onResize.apply(this,$(arguments))}},hide:function($super){if(this.fadeBackgroundElement!=null&&(this.options.fadeBackgroundOption.onHideEffect!=null||this.options.fadeBackgroundOption.hideEffect!=null)&&this.options.parallelBackgroundEffect==true){this.fadeBackgroundElement.hide();this.fadeBackgroundElement=null}$super()},onHide:function($super){if(this.fadeBackgroundElement!=null){this.fadeBackgroundElement.hide();this.fadeBackgroundElement=null}Event.stopObserving(this.element,"resize",this.onResizeHandler);Event.stopObserving(window,"scroll",this.onScrollHandler);this.onResizeHandler=null;this.onScrollHandler=null;if(this.options.shadow){this.oldParentElement.appendChild(this.oldElement);this.element.remove();this.element=this.oldElement;this.element.hide()}$super()},onShow:function($super){if(this.fadeBackgroundElement!=null){this.fadeBackgroundElement.onBrowserResize()}$super()}});