var tmr;
var t;
var thePage;
var theMask;
var strtd=false;

function ShowPage(url, w, h) {
	if (!strtd) {
		strtd=true;
		thePage = gObj();
		theMask = gObj2();
		pf = document.getElementById("thePageFrame");
		pf.src = url;
		pf.style.height=h + 'px';
		CenterPage(h);
		MaskSize();
		Shw(true);
		t = 0;
		sTmr();
	}
}

function HidePage() {
	if (!strtd) {
		strtd=true;
		t = -100;
		sTmr();
	}
}

function sTmr() {
	tmr = setInterval("PanelFade()",50);
}

function PanelFade() {
	var amt = Math.abs(t+=25);
	if(amt == 100) {
		pf = document.getElementById("thePageFrame");
		pf.style.visibility='Visible';
	}
	if(amt == 0 || amt == 100) {
		clearInterval(tmr);
		strtd=false;
	}
	amt = (amt == 100)?99.999:amt;
  	
	thePage.style.filter = "alpha(opacity:"+amt+")";
	thePage.style.KHTMLOpacity = amt/100;
	thePage.style.MozOpacity = amt/100;
	thePage.style.opacity = amt/100;

	theMask.style.filter = "alpha(opacity:"+(amt/2)+")";
	theMask.style.KHTMLOpacity = amt/200;
	theMask.style.MozOpacity = amt/200;
	theMask.style.opacity = amt/200;
	
	if(amt == 0) Shw(false);
}

function CenterPage(h) {
		var theBody = document.getElementsByTagName("BODY")[0];
		var ScrollTop=0;
		
		if (self.pageYOffset) // all except Explorer
		{
			ScrollTop=self.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
		{
			ScrollTop=document.documentElement.scrollTop;
		}
		else if (document.body) // all other Explorers
		{
			ScrollTop=document.body.scrollTop;
		}

		var scTop = parseInt(ScrollTop)-20;
		var scLeft = parseInt(theBody.scrollLeft)+8;
		
			
		//thePage.style.top = (scTop + ((getViewportHeight() - h) / 2)) + "px";
		//thePage.style.left =  (scLeft + ((getViewportWidth() - w) / 2)) + "px";
		thePage.style.top = (scTop + ((getViewportHeight() - h) / 2)) + "px";
		thePage.style.left =  (scLeft + ((getViewportWidth() - 685) / 2)) + "px";
		//thePage.style.marginLeft = "-" + parseInt(thePage.offsetWidth / 2) + "px";
		//thePage.style.marginTop = "-" + parseInt(thePage.offsetHeight / 2) + "px";
}

function gObj() {
	return document.getElementById("page");	
}

function gObj2() {
	return document.getElementById("mask");	
}

function Shw(b) {
	(b)? thePage.className = 'show':thePage.className = '';	
	(b)? theMask.className = 'show':theMask.className = '';	
	pf = document.getElementById("thePageFrame");
	if (!b) pf.style.visibility = 'Hidden';	
}

function MaskSize() {
	var winW = 0, winH= 0;
    var D = document;
    winH=Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );

    winW=Math.max(
        Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
        Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
        Math.max(D.body.clientWidth, D.documentElement.clientWidth)
    );

	theMask.style.width = winW + 'px';
	theMask.style.height = winH+ 'px';
}

function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 

	return window.undefined; 
}
function getViewportWidth() {
	var offset = 17;
	var width = null;
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
}

