window.addEvent("unload",function(){$$("div.glbox-box").destroy();$$("div.glbox-overlay").destroy()});var glBox=new Class({Implements:[Events,Options],presets:{infobox:null,closeOnBlur:false,modal:false,fixed:false,coordinates:null,borderColor:"#69c",borderOpacity:0.8,borderThickness:7,nooverlay:false,resizable:false,location:{x:100,y:100},topbar:null,bottombar:null,iframeOptions:null,overlayOffset:3,morphDuration:"100",size:{x:200,y:100},sizeLoading:{x:200,y:150},marginInner:{x:20,y:20},marginImage:{x:50,y:75},handler:false,target:null,closable:true,closeBtn:true,zIndex:65555,overlayOpacity:0.7,classContainer:"glbox-container",classOverlay:"glbox-overlay",overlayFx:{},resizeFx:{},contentFx:{},parse:false,parseSecure:false,ajaxOptions:{},onOpen:$empty,onClose:$empty,onUpdate:$empty,onResize:$empty,onMove:$empty,onShow:$empty,onHide:$empty},init:function(B){if(this.options){return this}this.presets=$merge(this.presets,B);this.options={};this.setOptions(this.presets);window.addEvent("resize",function(){this.resize();this.reposition()}.bind(this));window.addEvent("scroll",function(){this.reposition()}.bind(this));this.isOpen=this.isLoading=false;return this},build:function(){this.overlay=new Element("div",{styles:{zIndex:this.options.zIndex}});if(!this.options.nooverlay){$(document.body).adopt(this.overlay)}this.overlay.fade("hide");this.container=new Element("div");this.box=new Element("div",{"class":"glbox-box",styles:{"background-color":this.options.borderColor,top:this.options.location.y,left:this.options.location.x,padding:this.options.borderThickness,zIndex:this.options.zIndex+1}}).adopt(this.container);this.box.fade("hide");$(document.body).grab(this.box);this.doBaseLayout();this.doLayout();this.box.set("tween",{duration:this.options.morphDuration});this.overlay.set("tween",{duration:this.options.morphDuration});this.reposition();if(this.options.modal){this.overlay.setStyles({top:0,left:0});this.resize();this.overlay.fade(this.options.borderOpacity)}else{this.updateOverlay();this.overlay.fade(this.options.borderOpacity)}if(this.options.resizable){this.initBorderResizeEvents()}this.box.fade("in")},doBaseLayout:function(){this.mainContent=new Element("div",{"class":"glbox-content"});this.mainContent.inject(this.container);this.topbar=new Element("div",{"class":"glbox-bar"});this.bottombar=new Element("div",{"class":"glbox-bar"});if($(document.getElementById(this.options.topbar))){this.topbar.inject(this.container,"top");this.topbar.grab($(document.getElementById(this.options.topbar)))}var B=$(document.getElementById(this.options.bottombar));if(!B){B=$(this.options.bottombar)}if(B){B.setStyle("display","block");this.bottombar.inject(this.container);this.bottombar.grab(B)}},fromElement:function(F,H){if(this.isHidden){this.evoke();return true}this.init();this.element=$(F);this.url=((this.element)?(this.options.url||this.element.get("href")):F)||"";this.assignOptions(H);this.build();this.afterBuild();var G=this.options.handler;var E=false;return E},assignOptions:function(C){this.setOptions($merge(this.presets,C||{}));if(this.element&&this.options.parse){var D=this.element.getProperty(this.options.parse);if(D&&(D=JSON.decode(D,this.options.parseSecure))){this.setOptions(D)}}},afterBuild:function(){this.overlay.set("class",this.options.classOverlay);this.container.set("class",this.options.classContainer)},close:function(B){if(this.isHidden){return }this.box.fade("out");this.overlay.fade("out");this.isHidden=true},sleep:function(){this.box.fade("out");this.overlay.fade("out");this.isHidden=true},evoke:function(){if(!this.isHidden){return }this.fireEvent("onShow",[this.win]);this.overlay.fade(this.options.borderOpacity);this.box.fade("in");this.isHidden=false},showContent:function(){if(this.content.get("opacity")){this.fireEvent("onShow",[this.win])}this.fx.content.start(1)},hideContent:function(){if(!this.content.get("opacity")){this.fireEvent("onHide",[this.win])}this.fx.content.set(0)},initBorderResizeEvents:function(){if(!this.box){return }this.box.addEvent("mousemove",function(I){var H=1;var K=this.box.getStyle("left").toInt(),J=this.box.getStyle("top").toInt();var L=I.client.x-K,G=I.client.y-J;if(L<=this.options.borderThickness){H*=2}if(L>=(this.box.getSize().x-this.options.borderThickness)){H*=-2}if(G<=this.options.borderThickness){H*=3}if(G>=(this.box.getSize().y-this.options.borderThickness)){H*=-3}if(Math.abs(H)===2){this.box.setStyle("cursor","e-resize")}if(Math.abs(H)===3){this.box.setStyle("cursor","s-resize")}if(H===6){this.box.setStyle("cursor","se-resize")}if(H===-6){this.box.setStyle("cursor","ne-resize")}if(H===1){this.box.setStyle("cursor","")}}.bind(this))},updateOverlay:function(){if(!this.options.modal){this.overlay.setStyles({top:this.box.getCoordinates().top+this.options.overlayOffset,left:this.box.getCoordinates().left+this.options.overlayOffset,width:this.box.getCoordinates().width,height:this.box.getCoordinates().height})}},resize:function(){if(!this.options.modal){return }var I=document.getSize(),F=document.getScroll();var G=document.body.scrollHeight.toInt();if(Browser.Engine.gecko){G+=20}if(!Browser.Engine.webkit){G+=document.body.getStyle("margin-top").toInt()+document.body.getStyle("margin-bottom").toInt()}var H=((!Browser.Engine.trident)?"100%":window.getSize().x);this.overlay.setStyles({top:0,left:0,width:H,height:G});if(this.options.modal){var J=F.x+window.getSize().y;if(J>G){G=J}this.overlay.setStyles({width:H+"px",height:G+"px"})}else{}return this.fireEvent("onResize",[this.overlay,this.win])},reposition:function(){var F=0,E=0;if(this.options.fixed){if(Browser.Engine.trident4){var D=document.getScroll();this.box.setStyle("top",D.y+this.options.location.y);F=D.y;E=D.x;this.updateOverlay()}else{this.box.setStyle("position","fixed");this.overlay.setStyle("position","fixed")}}else{this.box.setStyle("position","absolute");this.overlay.setStyle("position","absolute")}if(this.options.modal){this.box.setStyles({top:(window.getSize().y-this.box.getCoordinates().height)/2+F,left:(window.getSize().x-this.box.getCoordinates().width)/2+E})}}});Element.implement({glBox:function(B){return new glBox(this,B)}});var glBoxiframe=new Class({Implements:glBox,Extends:glBox,initialize:function(D,C){C=$merge(C,{modal:true,fixed:true});return D.addEvent("click",function(A){A.stop();return !this.fromElement(D,C)}.bind(this))},doLayout:function(){if(this.iframe){this.iframe.destroy()}this.initIFrame(this.url);this.mainContent.empty();this.mainContent.grab(this.iframe);this.iframe.set("src",this.url);this.overlay.addEvent("click",function(B){this.close()}.bind(this))},initIFrame:function(B){this.iframe=new Element("iframe",{"class":"glbox-iframe",src:B,frameBorder:0,flex:0,width:this.options.size.x,height:this.options.size.y});return this.iframe}});var glBoxFloating=new Class({Implements:glBox,Extends:glBox,initialize:function(D,C){C=$merge(C,{borderOpacity:0.5,zIndex:1,onShow:function(B){var A=document.getScroll().y+window.getSize().y;if(this.box.getCoordinates().top>A){this.box.setStyle("top",A-this.box.getSize().y-10);this.updateOverlay()}}});this.initiated=false;D.addEvent("click",function(A){A.stop();if(this.initiated&&!this.isHidden){return }this.initiated=true;C=$merge(C,{location:{x:A.client.x,y:A.client.y}});this.fromElement(D,C);if(this.box&&!this.boxDrag){this.boxDrag=this.box.makeDraggable({onDrag:function(){this.updateOverlay()}.bind(this)});this.box.setStyle("cursor","move")}}.bind(this))},fixBox:function(){this.offsetTop=this.box.getCoordinates().top-document.getScroll().y;if(!Browser.Engine.trident4){this.box.setStyle("top",this.offsetTop);this.updateOverlay()}else{this.overlay.fade("hide")}this.options.fixed=true;this.reposition();this.box.setStyle("cursor","default");this.boxDrag.detach()},releaseBox:function(){this.options.fixed=false;this.reposition();if(!Browser.Engine.trident4){this.box.setStyle("top",document.getScroll().y+this.offsetTop)}else{this.overlay.fade("show")}this.updateOverlay();this.box.setStyle("cursor","move");this.boxDrag.attach()}});
