/** A covering element that cannot be moved
 *
 * Intended for use with XHTML documents (IE uses document.documentElement instead
 * of document.body for some things).
 * 
 * @author Erick S <esatire@gmail.com>
 * @version 1.3.4 23/10/2007 - Fixed appearance on HTML pages where body doesn't take the full screen
 * @copyright Atarim Group LTD.
 */ 


/**
 * @return {Object} With x and y properties.
 */
function getScreenCenter()
{
	var pos = new Object();
	pos.x = document.documentElement.scrollLeft + document.documentElement.clientWidth/2;
	if (window.innerHeight)
		pos.y = document.documentElement.scrollTop + window.innerHeight/2;	
	else
		pos.y = document.documentElement.scrollTop + document.documentElement.clientHeight/2;	
	return pos;
}

function FloaterBox()
{
	// private vars
	var myself = this;
	this.container = document.createElement("DIV");
	this.container.className = "FloaterBox";
	document.body.appendChild(this.container);
	this.hide = function()
	{
		FloaterBox.overlay.style.visibility = 'hidden';
		this.container.style.display = "none";
		//alert('hidden');
	}

	this.showCenter = function(w,h)
	{
		if (this.container.style.display != 'block') this.container.style.display = "block";
		// we gotta set width/height first, so x and y will be set correctly
		if (typeof (w) == 'undefined' || w == null)
		{
			w = this.container.firstChild.offsetWidth;
		}
		if (typeof (h) == 'undefined' || h == null)
		{
			h = this.container.firstChild.offsetHeight;
		}
		var pos = getScreenCenter();
		pos.x -= w/2;
		pos.y -= h/2;
		this.show(pos.x,pos.y,w,h);
	}
	
	this.show = function(x,y,w,h)
	{
		if (typeof (x) != 'undefined') this.container.style.left = x + "px";
		if (typeof (y) != 'undefined') this.container.style.top = y + "px";
		if (typeof (w) != 'undefined' && w != null) this.container.style.width = w +"px";
		if (typeof (h) != 'undefined' && h != null) this.container.style.height = h + 'px';
		if (this.container.style.display != 'block') this.container.style.display = "block";

		if (FloaterBox.overlay == null) FloaterBox.CreateOverlay();
		FloaterBox.overlay.style.width = document.documentElement.scrollWidth + 5 + 'px';
		//FloaterBox.overlay.style.width = document.documentElement.clientWidth + 'px';
		if (document.documentElement.clientHeight > document.documentElement.scrollHeight)
			FloaterBox.overlay.style.height = document.documentElement.clientHeight + 5 + 'px';
		else
			FloaterBox.overlay.style.height = document.documentElement.scrollHeight + 5 + 'px';	
			 
		FloaterBox.overlay.style.visibility = 'visible';
		// alert("w=" + w + " h=" + h + " x=" + x + " y="+y);		
	}

	this.setContents = function(contents)
	{
		// we reset his size here so show will calculate w/h correctly
		//this.container.style.height='0px';
		//this.container.style.width='0px';
		this.container.innerHTML = contents;
	}
}
/** Covers the screens in darkness */
FloaterBox.overlay		= null;
FloaterBox.CreateOverlay = function()
{
	FloaterBox.overlay = document.createElement('DIV');
	FloaterBox.overlay.className = 'FloaterPageOverlay';
	document.body.appendChild(FloaterBox.overlay);
}