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,automoveToBody:false});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.automoveToBody){if(this.oldParentElement==null){this.oldParentElement=this.element.up()}$(document.body).appendChild(this.element)}if(this.options.fadeBackground&&this.fadeBackgroundElement==null){Prototype.require("jojoFullscreenElement.js");var H=this.options.fadeBackgroundOption;H.zIndex=this.options.zIndex-2;if(!this.options.parallelBackgroundEffect){H.onShow=this.show.bind(this)}this.fadeBackgroundElement=new FullScreenElement("",H);this.fadeBackgroundElement.show();if(!this.options.parallelBackgroundEffect){return}}if(this.options.shadow){var D=this.element.up();if(this.oldParentElement==null){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 I=new Element("TR");A.appendChild(I);I.appendChild(new Element("TH",{"class":"TopLeftShadow"}));I.appendChild(new Element("TH",{"class":"TopShadow"}));I.appendChild(new Element("TH",{"class":"TopRightShadow"}));var I=new Element("TR");A.appendChild(I);I.appendChild(new Element("TH",{"class":"LeftShadow"}));I.appendChild(new Element("TD"));I.appendChild(new Element("TH",{"class":"RightShadow"}));var I=new Element("TR");A.appendChild(I);I.appendChild(new Element("TH",{"class":"BottomLeftShadow"}));I.appendChild(new Element("TH",{"class":"BottomShadow"}));I.appendChild(new Element("TH",{"class":"BottomRightShadow"}));this.element.appendChild(A);this.element.down("TD").appendChild(this.oldElement);if(Prototype.Browser.Gecko){var E=new Element("DIV");E.hide();E.appendChild(this.element);this.element.show();this.element=E}this.oldElement.show();D.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 J=this.element.getDimensions();this.element.hide();this.element.setStyle({visibility:"visible"});var C=parseInt(((dimension.clientWidth-J.width)/2)+dimension.offsetX);var B=parseInt(((dimension.clientHeight-J.height)/2)+dimension.offsetY);var G;var F;if(J.height>dimension.clientHeight){if(J.height>=dimension.height){F=0}else{F=[[0,B].max(),dimension.height-J.height].min()}}else{F=B}if(J.width>dimension.clientWidth){if(J.width>=dimension.width){G=0}else{G=[[0,C].max(),dimension.width-J.width].min()}}else{G=C}this.element.setStyle({top:F+"px",left:G+"px",zIndex:this.options.zIndex});this.onResizeHandler=this.onResize.bindAsEventListener(this);this.onScrollHandler=this.onScroll.bindAsEventListener(this);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(){if(this.options.onResize){this.options.onResize.apply(this,$(arguments))}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)}},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()}else{if(this.options.automoveToBody){this.oldParentElement.appendChild(this.element)}}$super()},onShow:function($super){if(this.fadeBackgroundElement!=null){this.fadeBackgroundElement.onBrowserResize()}$super()}});