var newDiv;
var topFactor;
var theCenter;
var theHTML;

function addLayer(theContent,theWidth,cMode){
	// Get width, height and cent properties from the XML
	topFactor = 100;
	theBorder = 18;
	leftCol = 320;
	
	var vWidth = f_clientWidth();
	vWidth = parseFloat(vWidth);
	theLeft = (vWidth/2)-(theWidth/2);

	divIdName = "pageOverlay";
	newdiv = ($(divIdName)) ? $(divIdName) : document.createElement('div');
	newdiv.setAttribute("id",divIdName);
	
	theCSS = "position:absolute; z-index:100; padding:0; margin:0; " +
		"width: " + (theWidth+(theBorder*2)) + "px; " + 
		"left :" + theLeft + "px; " +
		"top: " + (getScroll()+topFactor) + "px; " +
		"background: #FFFFFF; ";
	
	if(BrowserDetect.browser != "Chrome" && (BrowserDetect.version >=7 && BrowserDetect.browser == "Explorer")) theCSS = theCSS + "display: none;";

	theHTML = "<div style=\"padding:" + theBorder + "px; \" id=\"messageWindow\">" + theContent + "</div>";

	// load HTML in DIV
	newdiv.innerHTML = theHTML;
	if(!cMode){ newdiv.style.cssText = theCSS; }
	
	//Put new div into document Object
	if(!$(divIdName)){
		// load CSS for DIV
		document.body.appendChild(newdiv);
	}
	// initiate making it visible
	coverUp(cMode);
};

// This function detroy the coverup layer and the overlay layer
function removeOverlay(){
	//document.body.removeChild($('pageOverlay'));
	//document.body.removeChild($('pageCoverUp'));
	$('pageOverlay').fade({duration: 0.3, queue:'end'});
	$('pageCoverUp').fade({duration: 0.3, queue:'end'});
};

//this function appends a semi-transparent overlay to the DOM covering up ALL the document
function coverUp(cMode){
	document.body.style.cssText = document.body.style.cssText = "; height:100%";

	var divIdName = "pageCoverUp";
	var coverUp = ($(divIdName)) ? $(divIdName) : document.createElement('div');
	coverUp.setAttribute("id",divIdName);
	
	var vHeight = f_clientHeight();
	vHeight = parseFloat(vHeight);
	
	vWidth = "100%";
	addThis = "left:0px; top:0px; right:0px; bottom:0px;";

	if(!$(divIdName)){
		document.body.appendChild(coverUp);
	}

	if(cMode == 0){
		if((BrowserDetect.version >=7 && BrowserDetect.browser == "Explorer") || BrowserDetect.browser == "Firefox" || BrowserDetect.browser == "Chrome"){
			//coverUp.style.cssText = "z-index:2; position:absolute; " + addThis + "width:" + vWidth + "; height:" + vHeight + "px; background:black; display: none;";
			coverUp.style.cssText = "z-index:2; position:absolute; " + addThis + " background:black; display: none;";
		} else{
			coverUp.style.cssText = "z-index:2; position:absolute; " + addThis + "width:" + vWidth + "; height:" + vHeight + "px; background:url(images/ie6bg.gif) repeat;";
		}
		if($("pageCoverUp").style.display == "none"){
			$("pageCoverUp").appear({to: 0.5, duration: 0.3, queue:'end'}); 
			$("pageOverlay").appear({duration: 0.3, queue:'end'});
		}
	}
	
};


