/**
 * @author marc.zahn - mzahn@magix.net
 */
function Popup(id, centered, width, height)
{
	this.popup = new Object();
	
	this.popup['centered']	= centered;
	this.popup['width']		= width;
	this.popup['height']	= 'auto';
	this.popup['visible']	= true;
	this.popup['id']		= id;
}

Popup.prototype.setContent = function(content)
{
	this.popup['content'] = content;
}
Popup.prototype.show = function()
{
	var self = this;
	this.popup['layer']	= document.createElement('div');
	this.popup['layer'].style.display	= 'none';
	this.popup['layer'].id				= 'popup_' + this.popup['id'];
	
	if ((typeof this.popup['content']) == 'object')
		this.popup['layer'].appendChild(this.popup['content']);
	else
		this.popup['layer'].innerHTML		= this.popup['content'];
	
	if (this.popup['width'] != 'auto')
		this.popup['layer'].style.width	= this.popup['width'] + 'px';
	else
		this.popup['layer'].style.width	= 'auto';
	if (this.popup['width'] != 'auto')
		this.popup['layer'].style.height	= this.popup['height'];//this.popup['height'] + 'px';
	else
		this.popup['layer'].style.height	= 'auto';
	this.popup['layer'].style.position	= 'absolute';
	this.popup['layer'].style.zIndex	= '5';	
	
	document.body.appendChild(this.popup['layer']);
	this.popup['layer'].style.display		= 'block';
	if (this.popup['centered'])
	{
		var scrollY = 0;
		var scrollX = 0;
		if (getBrowser() == 'msie')
		{
			scrollY = document.documentElement.scrollTop;
			scrollX = document.documentElement.scrollLeft;
		}
		else
		{
			scrollY = window.pageYOffset;
			scrollX = window.pageXOffset;
		}
		this.popup['layer'].style.marginTop 	= (scrollY - this.popup['layer'].offsetHeight/2) + 'px';
		this.popup['layer'].style.top			= '50%';
		this.popup['layer'].style.marginLeft	= (scrollX - this.popup['layer'].offsetWidth/2) + 'px';
		this.popup['layer'].style.left			= '50%';
		
		window.onresize = 
		window.onscroll = function(e)
		{
			var scrollY = 0;
			var scrollX = 0;
			if (getBrowser() == 'msie')
			{
				if (document.body.scrollHeight <= document.documentElement.scrollTop + self.popup['layer'].offsetHeight)
					scrollY = document.body.scrollHeight - self.popup['layer'].offsetHeight;
				else
					scrollY = document.documentElement.scrollTop;
				document.title = 'ScrollTop: ' + document.documentElement.scrollTop + ', scrollheight: ' + document.body.scrollHeight;
				
				
				if (document.body.scrollWidth <= document.documentElement.scrollLeft + self.popup['layer'].offsetWidth)
					scrollX = document.body.scrollWidth - self.popup['layer'].offsetWidth;
				else
					scrollX = document.documentElement.scrollLeft;
			}
			else
			{
				scrollY = window.pageYOffset;
				scrollX = window.pageXOffset;
			}
			self.popup['layer'].style.marginTop		= (scrollY - self.popup['layer'].offsetHeight/2) + 'px';
			self.popup['layer'].style.marginLeft	= (scrollX - self.popup['layer'].offsetWidth/2) + 'px';
		}
	}
}
Popup.prototype.hide = function()
{
	this.popup['layer'].innerHTML = null;
	document.body.removeChild(this.popup['layer']);
	this.popup['visible']				= false;
}