// JavaScript Document

if(typeof OverlayGenerator == "undefined") var OverlayGenerator = new Object();
OverlayGenerator.create = function(title,content){
	//alert("Function Create Started OK!");
	
	this.domElement = document.createElement("div");
	this.domElement.id = "overlay";

	this.background = document.createElement("div");
	this.background.id = "overlay-background";
	
	this.foreground = document.createElement("div");
	this.foreground.id = "overlay-foreground";
	
	var sizer = document.createElement("div");
	sizer.className = "sizer";
	this.background.appendChild(sizer);
	
	var table = '<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"><tbody><tr><td align="center" valign="middle"></td></tr></tbody></table>';
	
	var container = document.createElement("div");
	container.id = "overlay-content";

	var header = document.createElement("div");
	header.id = "overlay-head";
	
	this.theTitle = document.createElement("div");
	this.theTitle.className = "title";
	
	this.theBody = document.createElement("div");
	this.theBody.id = "overlay-body";

	var footer = document.createElement("div");
	footer.id = "overlay-foot";
	
	var closeLink = document.createElement("a");
	closeLink.className = "close";
	closeLink.href = "javascript:void(0)";
	closeLink.onclick = closeOverlay;

	var closeImg = document.createElement("img");
	closeImg.src = "html/img/overlay_close.gif";
	closeImg.border = "0";
	
	closeLink.appendChild(closeImg);
	header.appendChild(this.theTitle);
	header.appendChild(closeLink);
	container.appendChild(header);
	container.appendChild(this.theBody);
	container.appendChild(footer);

	this.foreground.innerHTML = table;
	
	this.foreground.firstChild.firstChild.firstChild.firstChild.appendChild(container);
	
	this.domElement.appendChild(this.background);
	this.domElement.appendChild(this.foreground);
	
	this.init = false;
};
OverlayGenerator.create.prototype = {
	 show:function(){
		 if(!this.init){
			 this.init = true;
			 document.body.insertBefore(this.domElement, document.body.firstChild);
		 }
	 }
	,open:function(title,content){
		if(title != null) this.setTitle(title);
		if(content != null) this.setContent(content);
		this.show();
	 }
	,close:function(){
		if(this.init){
			document.body.removeChild(this.domElement);
			this.init = false;
		}
	 }
	,setTitle:function(title){ this.theTitle.innerHTML = title; }
	,setContent:function(content){ this.theBody.innerHTML = content; }
};
var Overlay = OverlayGenerator.create;

var overlayElement = null;

function openOverlay(title,content){

	if(overlayElement == null){
		overlayElement = new Overlay(title,content);
	}
	overlayElement.open(title,content);
}

function closeOverlay(){
	if(overlayElement != null) overlayElement.close();
}
