// Copyright (c) 2007-2008 WoollySheep
// <http://www.woolly-sheep.net>

var Overlay=new Class({Implements:[Events,Options],options:{"background":"#000000","opacity":0.9,"zIndex":300,"duration":200,"transition":"quad:in:out"},initialize:function(B,A){this.where=$(B)||$(document.body);
this.setOptions(($type(B)=="object")?B:A);this.overlay=new Element("div",{"styles":{"opacity":0,"display":"none","position":"absolute","top":0,"left":0,"cursor":"pointer","background-color":this.options.background,"z-index":this.options.zIndex}}).inject(document.body);
this.overlay.addEvent("click",this.hide.bind(this));this.fx=new Fx.Tween(this.overlay,"opacity",{duration:this.options.duration,transition:this.options.transition}).set(0);
this.open=false;return this},reposition:function(B){var A=this.where;B=B||A.getScrollSize();this.overlay.setStyles({top:A.getPosition().y||0,left:A.getPosition().x||0,width:B.x,height:B.y});
return this},show:function(){this.reposition().fx.start(this.options.opacity);this.overlay.setStyle("display","");
this.open=true;return this.fireEvent("onShow",this.overlay)},hide:function(){var A=this.overlay;this.reposition().fx.start(0).chain(function(){A.setStyle("display","none")
});this.open=false;return this.fireEvent("onHide",this.overlay)},toggle:function(){this[this.open?"hide":"show"]();
return this}})