function Popup()
{
	this.image_base_url = "";
}

Popup.prototype.init = function(solid, disableClickClosing, c)
{
	var opacity = 80;
	var filterStr = '';
	if (typeof solid == 'number') {
		opacity = solid;
	}
	filterStr = 'style="filter:alpha(opacity='+opacity+');-moz-opacity:.'+opacity+';opacity:.'+opacity+';"';
	if (typeof solid == 'boolean' && solid) {
		filterStr = '';
	}

	this.disableClickClosing = disableClickClosing ? disableClickClosing : false;
	this.c = c ? c : false;

	this.template = ''
	+'<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" ' + filterStr + '>'
		+'<tr>'
			+'<td>'
				+'<img src="'+this.image_base_url+'/popup_edge1.gif" width="6" height="6" alt="" border="0">'
			+'</td>'
			+'<td background="'+this.image_base_url+'/popup_border1.gif">'
				+'<img src="'+this.image_base_url+'/popup_border1.gif" width="1" height="6" alt="" border="0">'
			+'</td>'
			+'<td align="right">'
				+'<img src="'+this.image_base_url+'/popup_edge2.gif" width="6" height="6" alt="" border="0">'
			+'</td>'
		+'</tr>'
		+'<tr>'
			+'<td background="'+this.image_base_url+'/popup_border2.gif">'
				+'<img src="'+this.image_base_url+'/popup_border2.gif" width="6" height="1" alt="" border="0">'
			+'</td>'
			+'<td width="100%" height="100%" bgcolor="#F7F8FA" valign="top">&nbsp;</td>'
			+'<td background="'+this.image_base_url+'/popup_border3.gif">'
				+'<img src="'+this.image_base_url+'/popup_border3.gif" width="6" height="1" alt="" border="0">'
			+'</td>'
		+'</tr>'
		+'<tr>'
			+'<td>'
				+'<img src="'+this.image_base_url+'/popup_edge3.gif" width="6" height="6" alt="" border="0">'
			+'</td>'
			+'<td width="100%" background="'+this.image_base_url+'/popup_border4.gif">'
				+'<img src="'+this.image_base_url+'/popup_border4.gif" width="1" height="6" alt="" border="0">'
			+'</td>'
			+'<td align="right">'
				+'<img src="'+this.image_base_url+'/popup_edge4.gif" width="6" height="6" alt="" border="0">'
			+'</td>'
		+'</tr>'
	+'</table>';

	this.div = document.createElement('DIV');
	this.div.className = "select-free";
	this.div.style.display = "none";
	this.div.style.overflow = "hidden";
	this.div.style.position = "absolute";
	this.div.innerHTML = this.template;
	document.body.appendChild(this.div);
	
	this.overlay = document.createElement('DIV');
	this.overlay.style.display = "none";
	this.overlay.style.position = "absolute";
	this.overlay.style.overflow = "hidden";
	this.overlay.innerHTML = '';
	document.body.appendChild(this.overlay);
	
	this.frame = document.createElement('IFRAME');
	this.frame.className = "select-free-iframe";
	this.div.appendChild(this.frame);

	
	var me = this;
	if (!this.disableClickClosing) 
		this.overlay.onclick = function() {me.hide();};
	
	
	this.div.zIndex = 1000;
	this.overlay.zIndex = 1010;
	
	this.sideOffsetValue = 20;
	this.gapValue = 30;

	this.initialized = false;
}

Popup.prototype.display = function(callerID, content, width, height)
{
	if (callerID != null) 
	{
		this.caller = document.getElementById(callerID);
	};

	if (this.caller != null) {
		var callerLeft = callerTop = 0;
		var node = this.caller;
		if (node.offsetParent) {
			callerLeft = node.offsetLeft
			callerTop = node.offsetTop
			while (node = node.offsetParent) {
				callerLeft += node.offsetLeft
				callerTop += node.offsetTop
			}
		}
		
		var divWidth = width ? width : this.div.style.width;
		var divHeight = height ? height : this.div.style.height;
		
//		var divLeft = callerLeft + this.caller.offsetWidth + this.sideOffsetValue;
//		var divTop = callerTop;
//
//		if (divLeft + divWidth + this.gapValue > screen.width) {
//			divLeft = callerLeft - divWidth - this.sideOffsetValue;
//		}
//
//		if (divTop + divHeight + this.gapValue > screen.height - 150) {
//			divTop = callerTop - divHeight + this.caller.offsetHeight;
//		}
//		
//		if (divLeft < 0) {
//			divLeft = 0;
//		}
//		
//		if (divTop - document.body.scrollTop < 0) {
//			divTop = document.body.scrollTop;
//		}
		
		wsize = getWindowSize();
		wscroll = getScrollXY();
		divLeft = (wsize[0]-divWidth)/2 + wscroll[0];
		divTop = (wsize[1]-divHeight)/2 + wscroll[1];
		
		this.div.style.left = divLeft;
		this.div.style.top = divTop;
		this.overlay.style.left = divLeft + 3;
		this.overlay.style.top = divTop + 3;
		
		this.frame.style.left = -100;
		this.frame.style.top = -100;		

		this.initialized = true;
	};
	
	if (width != null && height != null){
		this.div.style.width = width;
		this.div.style.height = height;
		this.overlay.style.width = width - 6;
		this.overlay.style.height = height - 6;
		this.frame.width = width;
		this.frame.height = height;
	};
	
	if (content != null){
		this.overlay.innerHTML = content;
		
		if (this.disableClickClosing && !this.c) {
			var closeDiv = document.createElement('DIV');
			var closeLink = document.createElement('A');
			closeDiv.align = 'right';
			closeDiv.style.padding = '5px 10px 0px 0px;';
			closeDiv.style.fontSize = '11px';			
			var me = this;
			closeLink.onclick = function() {me.hide(); return false};
			closeLink.href = "#";
			closeLink.innerHTML = "Close";
			closeDiv.appendChild(closeLink);
			this.overlay.appendChild(closeDiv);
		};
	};	
	
	if (this.initialized){
		this.div.style.display = "block";
		this.overlay.style.display = "block";
	};
}

Popup.prototype.hide = function()
{
	this.div.style.display = "none";
	this.overlay.style.display = "none";
	this.frame.style.left = 0;
	this.frame.style.top = 0;
	this.frame.width = 0;
	this.frame.height = 0;
}
