function menuSelect(index) {
	// give headers a nice color
	headers = document.getElementById('header').getElementsByTagName('h3');
	for(i=0; i<headers.length; i++) {
		// selected one will be white others blue
		newColor = "#3399CC";
		if ((i+1) == index) {
			newColor = "#FFFFFF";
		}
		// assign color to link
		childs = headers[i].childNodes;
		for (j=0; j<childs.length; j++) {
			if (childs[j].nodeName == "A") {
				childs[j].style.color = newColor;
			}
		}
	}
	// show corresponding menu img
	var menuTabImg = document.getElementById('menuimg');
	menuTabImg.src = "./images/rcg/menu" + index + "G.jpg";
	
	// show correct submenu list
	submenus = document.getElementById('header').getElementsByTagName('ul');
	for(i=0; i<submenus.length; i++) {
		//submenus[i].style.position = "absolute";
		if ((i+1) == index) {
			// show this list
			submenus[i].style.display = "inline";
		} else {
			// hide this list
			submenus[i].style.display = "none";
		}
	}
	

}

function renderMenu() {
	var isIE = false;
	if (document.all) isIE = true;

	// level 1 menu headers
	headers = document.getElementById('header').getElementsByTagName('h3');
	for(i=0; i<headers.length; i++) {
		headers[i].style.position = "absolute";
		var top = 30;
		if (isIE) top = 40; // IE scales differently
		headers[i].style.top = top + "px";
		headers[i].style.left = "" + ((180 * i) + 100) + "px";
		headers[i].style.width = "180px";
	}
	// Fix head block
	if (isIE) {
		var header = document.getElementById('header');
		header.style.height = "265px";
	}
}

String.prototype.endsWith = function(str) {return (this.match(str+"$")==str)}

window.onload=function() {
	renderMenu();

	var select = 1;
	var page = window.location.href + "";
	//if (page.endsWith(".html")) { // Based on the fact that main menu 2 only contains static content pages
	if (page.indexOf("page/") > 0) {
		select = 2;
	}
	menuSelect(select);
}

