﻿// Hides and shows submenus and highlights appropriate button
function subnav(menuName, buttonName) {

	// detect modern, DOM-compliant browsers
	if (!document.getElementById) return;

	var menuName = document.getElementById(menuName);

	if (menuName.style.display == "none") {
		menuName.style.display = "";
		//if (buttonName.className.indexOf("selected") == -1) {
		buttonName.className = stringReplace(buttonName.className, "menu", "menu-s");
		//}
	}

	else {
		menuName.style.display = "none";
		//if (buttonName.className.indexOf("selected") == -1) {
		buttonName.className = stringReplace(buttonName.className, "menu-s", "menu");
		//}
	}
}


function stringReplace(theString, replaceMe, withMe) {
	var rExp;
	var temp = "";
	var newReplaceMe = "";
	for (var x = 0; x < replaceMe.length; x++) {
		temp = replaceMe.substr(x, 1);
		if (
            temp == "$" ||
            temp == "^" ||
            temp == "*" ||
            temp == "(" ||
            temp == ")" ||
            temp == "+" ||
            temp == "?" ||
            temp == "\\"
           ) {
			temp = "\\" + temp;
		}
		newReplaceMe += temp
	}
	rExp = new RegExp(newReplaceMe, "gi");
	results = theString.replace(rExp, withMe);
	return results;
}

function navTracking() {
	if (document.getElementById != null) {
		var navBox = document.getElementById('nav');
		if (navBox != null) {
			var navAnchors = navBox.getElementsByTagName('a');
			for (i = 0; i < navAnchors.length; i++) {
				if (navAnchors[i].className == 'menu') continue;
				var href = new String(navAnchors[i].href);
				if (href.indexOf('window.open') != -1) continue;
				navAnchors[i].href += ((href.indexOf('?') != -1) ? '&' : '?') + "CM.src=Navigation";
			}
		}
	}
}

var chnlPath = "";
if (document.location.href.indexOf("invasion") != -1) {
	chnlPath = "games";
}
else if (document.location.href.indexOf("playgames") != -1) {
	chnlPath = "gamesplay";
}
else if ((pagename == "comcast.html") || (pagename == "home.html") || (pagename == "explore.html")) {
	chnlPath = "home";
}
else {
	chnlPath = getFirstFolder();
}

