var Mask=new Class({Implements:[Options,Events],Binds:["resize"],options:{style:{},"class":"mask",maskMargins:false,useIframeShim:true},initialize:function(B,A){this.target=document.id(B)||document.body;this.target.store("mask",this);this.setOptions(A);this.render();this.inject();},render:function(){this.element=new Element("div",{"class":this.options["class"],id:this.options.id||"mask-"+$time(),styles:$merge(this.options.style,{display:"none"}),events:{click:function(){this.fireEvent("click");if(this.options.hideOnClick){this.hide();}}.bind(this)}});this.hidden=true;},toElement:function(){return this.element;},inject:function(B,A){A=A||this.options.inject?this.options.inject.where:""||this.target==document.body?"inside":"after";B=B||this.options.inject?this.options.inject.target:""||this.target;this.element.inject(B,A);if(this.options.useIframeShim){this.shim=new IframeShim(this.element);this.addEvents({show:this.shim.show.bind(this.shim),hide:this.shim.hide.bind(this.shim),destroy:this.shim.destroy.bind(this.shim)});}},position:function(){this.resize(this.options.width,this.options.height);this.element.position({relativeTo:this.target,position:"topLeft",ignoreMargins:!this.options.maskMargins,ignoreScroll:this.target==document.body});return this;},resize:function(A,E){var B={styles:["padding","border"]};if(this.options.maskMargins){B.styles.push("margin");}var D=this.target.getComputedSize(B);if(this.target==document.body){var C=window.getSize();if(D.totalHeight<C.y){D.totalHeight=C.y;}if(D.totalWidth<C.x){D.totalWidth=C.x;}}this.element.setStyles({width:$pick(A,D.totalWidth,D.x),height:$pick(E,D.totalHeight,D.y)});return this;},show:function(){if(!this.hidden){return this;}this.target.addEvent("resize",this.resize);if(this.target!=document.body){document.id(document.body).addEvent("resize",this.resize);}this.position();this.showMask.apply(this,arguments);return this;},showMask:function(){this.element.setStyle("display","block");this.hidden=false;this.fireEvent("show");},hide:function(){if(this.hidden){return this;}this.target.removeEvent("resize",this.resize);this.hideMask.apply(this,arguments);if(this.options.destroyOnHide){return this.destroy();}return this;},hideMask:function(){this.element.setStyle("display","none");this.hidden=true;this.fireEvent("hide");},toggle:function(){this[this.hidden?"show":"hide"]();},destroy:function(){this.hide();this.element.destroy();this.fireEvent("destroy");this.target.eliminate("mask");}});Element.Properties.mask={set:function(B){var A=this.retrieve("mask");return this.eliminate("mask").store("mask:options",B);},get:function(A){if(A||!this.retrieve("mask")){if(this.retrieve("mask")){this.retrieve("mask").destroy();}if(A||!this.retrieve("mask:options")){this.set("mask",A);}this.store("mask",new Mask(this,this.retrieve("mask:options")));}return this.retrieve("mask");}};Element.implement({mask:function(A){this.get("mask",A).show();return this;},unmask:function(){this.get("mask").hide();return this;}});