
function Popup()
{
	this.id = 'popup-' + parseInt(Math.random() * 100000000);
	
	this.overlay = false;
	
	this.container = false;
	this.content = false;
	this.closeButton = false;
	
	this.init = function()
	{
		this.overlay = new Overlay();
	}
	
	this.align = function()
	{
		var p = getScrollPosition();
		var d = getViewPortDimensions();
		
		this.container.style.top = p.y + Math.max(10, (d.h - parseInt(this.content.style.height)) / 2) + "px";
		this.container.style.left = p.x + Math.max(10, (d.w - parseInt(this.content.style.width)) / 2) + "px";
	}
	
	this.show = function(props)
	{
		if (!defined(props))
		{
			alert('no props');
			var props = new Object();
		}
		if (!defined(props.content))
		{
			props.content = '&nbsp;';
		}
		
		this.container = document.createElement('div');
		this.container.setAttribute('id', this.id);
		this.container.style.backgroundColor = '#fff';
		this.container.style.border = '1px solid #000';
		this.container.style.padding = '5px';
		this.container.style.position = 'absolute';
		
		
		this.content = document.createElement('div');
		this.content.style.width = '100px';
		this.content.style.height = '100px';
		
		if (props.width)
		{
			this.content.style.width = props.width;
		}
		if (props.height)
		{
			this.content.style.height = props.height;
		}
		
		this.align();
		
		this.content.innerHTML = props.content;
		
		this.content.style.background = 'url(../images/wait.gif) 50% 50% no-repeat';
		this.container.appendChild(this.content);
		
		this.closeButton = document.createElement('input');
		this.closeButton.setAttribute('class', 'close-button');
		this.closeButton.style.position = 'absolute';
		this.closeButton.style.top = '2px';
		this.closeButton.style.right = '2px';
		this.closeButton.type = 'button';
		this.closeButton.value = 'X';
		
		addListener(this.closeButton, 'click', onClose);
		
		this.container.appendChild(this.closeButton);
		
		this.overlay.show();
		
		this.overlay.addBlurFunction(onClose);
		document.body.appendChild(this.container);
		
	}

	this.close = function(e)
	{
		this.container.style.display = 'none';
		this.overlay.hide();
	}
	
	this.init();
}

function onClose(e)
{
	p.close(e);
}



function addListener(element, type, expression, bubb)
{
	bubb = bubb || false;

	if(window.addEventListener) {
		element.addEventListener(type, expression, bubb);
		return true;
	} 
	else if(window.attachEvent) {
		element.attachEvent('on' + type, expression);
		return true;
	} 
	else return false;
}


var ev;
function myOut(e)
{
	ev = e;
	alert(e);
}
