var sstrStay = '';
var sstrOn = '';
var sintTimer = 0;
var sarrItems = ['managedservices', 'wirelessservices', 'networking','about'];

function setClassName(strClassID, strClassName) {
	var objC = document.getElementById(strClassID);
	objC.className = strClassName;
}

function clearMenuStay(strID) {
	sstrStay = '';
	clearTimeout(sintTimer);
	sintTimer = setTimeout('MenuHide(\'' + strID + '\')', 500);
}

//Should really be called: menu off if not highlighted...
//only do MenuOff if the current page is different from the strID page (i.e. user's not currently viewing it)
function MenuOffIf(strID, gstrScript) {
	
	clearMenuStay(strID);
	
	if (gstrScript.indexOf(strID) < 0) {
		//The pageID is not in the highlighted page string: user is not browsing the page
		MenuOff(strID);	
	}	
	else {
		//It is highlighted, but for a drop down menu we need to change the background img	
		setClassName('cls_' + strID, 'topmenuon');
	}	
}

function MenuOn(strID, blnRight) {

	setClassName('cls_' + strID, 'topmenuon');
	sstrStay = strID;

	if (strID != sstrOn) {
		sstrOn = strID;
		var objN = document.getElementById('nav_' + strID);
		var objM = document.getElementById('menu_' + strID);

		if (objN != null && objM != null) {
			if (blnRight) {
				objM.style.left = (getTrueOffSet(objN, "left") - (objM.offsetWidth - objN.offsetWidth)) + 'px';
			}
			else {
				objM.style.left = (getTrueOffSet(objN, "left") - 1) + 'px';
			}
			objM.style.top = (getTrueOffSet(objN, "top")+39) + 'px';
			objM.style.visibility = 'visible';
		}
		MenuAllHide(strID);
	}
}

function MenuStay(strID) {
	setClassName('cls_' + strID, 'topmenuon');
	sstrStay = strID;
}

function MenuOff(strID) {
	clearMenuStay(strID);
	setClassName('cls_' + strID, '');
}

function MenuAllOff() {
	sstrStay = '';
	sstrOn = '';
	clearTimeout(sintTimer);
	MenuAllHide();
}

function MenuHide(strID) {
	if (strID != sstrStay) {
		if (strID == sstrOn) sstrOn = '';
		var objM = document.getElementById('menu_' + strID);
		objM.style.visibility = 'hidden';
	}
}

function MenuAllHide(strID) {
	var intCount, strItem;
	for (intCount = 0; intCount < sarrItems.length; intCount++) {
		strItem = sarrItems[intCount];
		if (strID != strItem) MenuHide(strItem);
	}
}

function getTrueOffSet(obj, strPos)
{
	var offsetStr="offset" + (strPos.toLowerCase()=="top" ? "Top" : strPos.toLowerCase()=="top" ? "Top" : "Left");
	var offsetVal=eval("obj." + offsetStr);
	while (obj.offsetParent != null)
	{
		offsetVal += eval("obj.offsetParent." + offsetStr);
		obj=obj.offsetParent;
	}
	return(offsetVal);
}
function ChangeImage(strId, strSrc){
	var objImage = document.getElementById('img' + strId).src = '/images/' + strSrc;
}
