var objCurMenu;
var objCurNav;
				
function PageStart(tCurMenu)
{
	Resize();
	window.onresize = Resize;
	var tCurMenu = document.getElementById("tCurMenu").value;
	if(tCurMenu != "")
		ShowSubNav(document.getElementById("menu" + tCurMenu).parentNode, "nav" + tCurMenu);
}

function Resize()
{
	// Center page in window
	var screenwidth = document.body.clientWidth;
    var screenheight = document.body.clientHeight;
	
	var objStyle = document.getElementById("mainStyle");
	if(objStyle){
		var leftPos = (screenwidth - objStyle.style.posWidth) / 2;
		var topPos = (screenheight - objStyle.style.posHeight) / 3;
		if(leftPos < 0)
			leftPos = 0;
		if(topPos < 0)
			topPos = 0;
		objStyle.style.posLeft = leftPos;
		objStyle.style.posTop = topPos;
		objStyle.style.visibility = "visible";
	}
}
				
function ShowSubNav(objParent, tNavMenu)
{
	if(objCurMenu) {
		var parent = objCurMenu.parentNode;
		objCurMenu = null;
		LowlightMainMenu(parent);
	}
		
	var objImg;
	for(var l = 0; l < objParent.childNodes.length; l++) {
		if(objParent.childNodes.item(l).nodeType == 1) {
			objImg = objParent.childNodes.item(l);
			break;
		}
	}
	if(!objImg)
		throw "Img tag not found";

	objCurMenu = null;
	HighlightMainMenu(objParent);
	objCurMenu = objImg;

	var objMenu;
	if(!tNavMenu)
		objMenu = document.getElementById("navNoMenu");
	else
		objMenu = document.getElementById(tNavMenu);
			
	if(!objMenu)
		throw "Menu not found";
			
	if(objCurNav)
		objCurNav.style.visibility = "hidden";

	objCurNav = objMenu;
	objCurNav.style.visibility = "visible";
		
	if(tNavMenu) {
		objMenu = document.getElementById("navNoMenu");
		if(!objMenu)
			throw "No default menu found (navNoMenu)";
		objMenu.style.visibility = "hidden";
	}
}


function HighlightAndShow(objParent)
{
	var objImg;
	for(var l = 0; l < objParent.childNodes.length; l++) {
		if(objParent.childNodes.item(l).nodeType == 1) {
			objImg = objParent.childNodes.item(l);
			break;
		}
	}
	if(!objImg)
		throw "Img tag not found";

	if(objImg == objCurMenu)
		return;
			
	var r;
	r = objImg.src.search('_dn.gif');
	if(r != -1) {
		// Found (already down)
	} else {
		// Not found (up)
		r = objImg.src.search('.gif');
		if(r == -1) {
			throw "Menu images must be .gifs";
		} else {
			objImg.src = objImg.src.slice(0, r) + "_dn.gif";
//			ShowSubNav(objParent, "nav" + objImg.id.slice(4));
		}
	}
}


function HighlightMainMenu(objParent)
{
	var objImg;
	for(var l = 0; l < objParent.childNodes.length; l++) {
		if(objParent.childNodes.item(l).nodeType == 1) {
			objImg = objParent.childNodes.item(l);
			break;
		}
	}
	if(!objImg)
		throw "Img tag not found";

	if(objImg == objCurMenu)
		return;
			
	var r;
	r = objImg.src.search('_dn.gif');
	if(r != -1) {
		// Found (already down)
	} else {
		// Not found (up)
		r = objImg.src.search('.gif');
		if(r == -1) {
			throw "Menu images must be .gifs";
		} else {
			objImg.src = objImg.src.slice(0, r) + "_dn.gif";
		}
	}
}


function LowlightMainMenu(objParent)
{
	var objImg;
	for(var l = 0; l < objParent.childNodes.length; l++) {
		if(objParent.childNodes.item(l).nodeType == 1) {
			objImg = objParent.childNodes.item(l);
			break;
		}
	}
	if(!objImg)
		throw "Img tag not found";			
		
	if(objImg == objCurMenu)
		return;
		
	var r;
	r = objImg.src.search('_dn.gif');
	if(r == -1) {
		// Not found (already up)
	} else {
		// Found (up)
		objImg.src = objImg.src.slice(0, r) + ".gif";
	}
}
	

