var sstrStay = '';
var sstrOn = '';
var sintTimer = 0;
var sarrItems = ['pianomoving', 'pianohire', 'pianoservices', 'pianomovingquotes', 'aboutus'];

function MenuOn(strID, blnRight) {
	sstrStay = strID;
	if (strID != sstrOn) {
		sstrOn = strID;
		var objN = document.getElementById('nav_' + strID);
		var objM = document.getElementById('menu_' + strID);
		var objC = document.getElementById('cls_' + strID);
		objC.className = 'menuNavOn';
		
		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")+ 35) + 'px';
			objM.style.top = (getTrueOffSet(objN, "top")+ 35) + 'px';
			objM.style.visibility = 'visible';
		}
		MenuAllHide(strID);
	}
}

function MenuStay(strID) {
	sstrStay = strID;
	var objC = document.getElementById('cls_' + strID);
	objC.className = 'menuNavOn';
}

function MenuOff(strID) {
	sstrStay = '';
	clearTimeout(sintTimer);
	sintTimer = setTimeout('MenuHide(\'' + strID + '\')', 500);
	var objC = document.getElementById('cls_' + strID);
	objC.className = 'menuNav';
}

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);
}

//This is not for the menu but this seemed to be a good spot to put it in nevertheless as it gets called from many places
function Popup(strURL, strName, intWidth, intHeight, strStatus, strScroll, strResize, strToolbar, strMenu, intTop, intLeft) {
	if (!strURL) {
		alert('A link must be specified when using the Popup function.');
	}
	else {
		window.name = 'popupopener';
		var strTop, strLeft;
		if (!strName) strName = 'popup';
		if (!intWidth) intWidth = 600;
		if (intWidth > (window.screen.width - 25)) intWidth = (window.screen.width - 25);
		if (!intHeight) intHeight = 400;
		if (intHeight > (window.screen.height - 125)) intHeight = (window.screen.height - 125);
		if (!strStatus) strStatus = 'yes';
		if (!strScroll) strScroll = 'yes';
		if (!strResize) strResize = 'yes';
		if (!strToolbar) strToolbar = 'no';
		if (!strMenu) strMenu = 'no';
		if (intTop && !isNaN(intTop)) strTop = ',top=' + intTop;
		if (intLeft && !isNaN(intLeft)) strLeft = ',left=' + intLeft;
		var objWindow = window.open(strURL, strName, 'width=' + intWidth + ',height=' + intHeight + ',status=' + strStatus + ',scrollbars=' + strScroll + ',resizable=' + strResize + ',toolbar=' + strToolbar + ',menubar=' + strMenu + strTop + strLeft);
		objWindow.focus();
	}
}

function CloseWindow() {
	if (top.opener) top.close();
	else window.location.href = '/';
}
