/**
 * @author rico
 * @version 1.0
 */

/*#####################################################################
	Overlay
#####################################################################*/

function Overlay()
{
	//-----------------------------------------------------------------
	
	var _self, bodyCt, overlay, overlayIframe, content, zIndex, visible;
	
	//-----------------------------------------------------------------
	/**
	 * 
	 * @return void
	 */
	function __construct() {
		_self = this;
		content = null;
		zIndex = 5000;
		visible = false;
		window.addEvent('resize',function(){
			resize();
		});
	}
	
	//-----------------------------------------------------------------
	/**
	 * 
	 * @return void
	 */
	function createOverlay()
	{
		bodyCt = document.getElements("BODY")[0];
		overlay = new Element('div');
		overlayIframe = new Element('iframe');
		overlayMessageBox = null;
		
		overlay.id = "overlay";
		overlay.setOpacity(0.4);
		overlayIframe.id	= 'overlayIframe';
		overlayIframe.setOpacity(0.001);
		
		bodyCt.appendChild(overlay);
		bodyCt.appendChild(overlayIframe);
	}
	//-----------------------------------------------------------------
	/**
	 * 
	 * @param {Object} content
	 * @return void
	 */
	this.show = function(a_content)
	{
		if(!overlay) { createOverlay(); }
		
		overlayIframe.style.zIndex = zIndex;
		overlay.style.zIndex = zIndex+1;
		
		if(a_content)
		{
			content = $(a_content);
			content.oldStyle = content.style.textCss;
			content.style.zIndex = zIndex+2;
			content.style.display = "block";
		}
		
		resize();
		
		overlayIframe.style.display = "block";
		overlay.style.display = "block";
		visible = true;
	}
	
	//-----------------------------------------------------------------
	/**
	 * 
	 * @return void
	 */
	this.hide = function()
	{
		content.style.textCss = content.oldStyle;
		content.style.display = "none";
		overlay.style.display = "none";
		overlayIframe.style.display = "none";
		visible = false;
		content = null;
	}
	
	//-----------------------------------------------------------------
	/**
	 * 
	 * @return void
	 */
	function resize() {
		if(visible === false) return;
		debug(12);
		overlay.style.width = "0px";
		overlay.style.height = "0px";
		overlayIframe.style.width = "0px";
		overlayIframe.style.height = "0px";
		var w = window.getScrollSize().x;
		var h =  window.getScrollSize().y;
		overlay.style.width = w + "px";
		overlay.style.height = h + "px";
		overlayIframe.style.width = w + "px";
		overlayIframe.style.height = h + "px";
		if( content != null ) {
			content.style.left = (w/2) - (content.offsetWidth/2) + "px";
			content.style.top = (h/2) - (content.offsetHeight/2) + "px";
		}
	}
	
	//-----------------------------------------------------------------
	/**
	 * 
	 * @return {Boolean} visible
	 */
	this.isVisible = function() {
		return visible;
	}
	
	//-----------------------------------------------------------------
	
	__construct();
	
	//-----------------------------------------------------------------
	
}