/**
 * @author reeko
 */

var Overlay = {
	box:null,
	iFrame:null,
	content:null,
	
	opacity:0.8,
	color:"#FFFFFF",
	zIndex:2000,
	
	init:function()
	{
		if(this.box === null)
		{
			var bodyCt = document.getElements("BODY")[0];
			this.box = new Element('div');
			this.box.setOpacity(this.opacity);
			this.box.style.backgroundColor = this.color;
			this.box.style.display="none";
			this.box.style.position="absolute";
			this.box.style.top="0px";
			this.box.style.left="0px";
			this.box.style.zIndex=this.zIndex;
			
			this.iFrame = new Element('iframe');
			this.iFrame.setOpacity(0.001);
			this.iFrame.style.display="none";
			this.iFrame.style.position="absolute";
			this.iFrame.style.top="0px";
			this.iFrame.style.left="0px";
			this.iFrame.style.margin="0px";
			this.iFrame.style.padding="0px";
			this.iFrame.style.border="none";
			this.iFrame.frameborder="0";
			this.iFrame.style.zIndex=this.zIndex-1;
			
			bodyCt.appendChild(this.box);
			bodyCt.appendChild(this.iFrame);
		}
	},
	
	show:function(element)
	{
		this.init();
		this.hide();
		
		var w = window.getSize().x;
		var h = window.getScrollSize().y;
		
		this.box.style.width = w + "px";
		this.box.style.height = h + "px";
		this.iFrame.style.width = w + "px";
		this.iFrame.style.height = h + "px";
		
		this.iFrame.style.display="block";
		this.box.style.display="block";
		
		if (element) {
			this.content = $(element);
			this.content.style.zIndex = this.zIndex + 1;
			this.content.style.display = "block";
			this.content.style.left = (w / 2) - (this.content.offsetWidth / 2) + "px";
			this.content.style.display="block";
			this.content.style.top = (window.getSize().y/2)-(this.content.offsetHeight/2)+window.getScroll().y+"px";
		}
	},
	
	hide:function()
	{
		if(this.content)
		{
			this.content.style.display = "none";
			this.content = null;
		}
		this.box.style.display="none";
		this.iFrame.style.display="none";
	}
}
