
var menuTimer; //timer used to hide menu
var currentMenu; //place holder for the current menu name
var menuDelay = 50; //delay in miliseconds before hiding a menu

function showMenu ( menuId, srcName ) {
	//show the supplied menuId under the supplied source menu Name
	
	//check to see if we're mousing over the current menu
	if ( menuId == currentMenu ) {
		clearTimeout(menuTimer);//yes, stop trying to hide this menu
	} else {
		hideMenu (currentMenu); //no, hide the last menu
	}
	currentMenu = menuId;
	
	var srcEl = document[srcName]; //get a handle on the source element
	if ( !srcEl ) return false;
	
	//determine the coordinates for the dropdown
	var newY = getAbsoluteTop(srcEl) + srcEl.offsetHeight;
	var newX = getAbsoluteLeft(srcEl);
	
	var el = document.getElementById( menuId ); //get a handle on the element
	if ( el ) {
		el.style.display = "block";
		el.style.left = newX;
		el.style.top = newY;
//below line commented out by EB/////////////
// el.style.width = srcEl.offsetWidth; //////
/////////////////////////////////////////////
		setUnder(el, menuId);
	}
	

}

function hideMenu ( menuId ) {
	//hide the supplied menu id
	//use a timer so that we can add a delay to the hiding of the menu
	var timeFun = "menu_HideMenu(\"" + menuId + "\");"
	menuTimer = setTimeout(timeFun, menuDelay);
}

function menu_HideMenu ( menuId ) {
	//hide the menu.
	var el = document.getElementById( menuId);
	if ( el ) {
		el.style.display = "none";
		killUnder(menuId)
	}
}


function getAbsoluteLeft(el) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	o = el;
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
			oParent = o.offsetParent    // Get parent object reference
			oLeft += oParent.offsetLeft // Add parent left position
			o = oParent
	}
	// Return left postion
	return oLeft
}

function getAbsoluteTop(el) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	o = el;
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
			oParent = o.offsetParent  // Get parent object reference
			oTop += oParent.offsetTop // Add parent top position
			o = oParent
	}
	// Return top position
	return oTop
}


function setUnder(el, menuId) {
	var elU = document.getElementById(menuId + "_under");
	if (elU) {
		elU.style.display = "block";
		elU.style.width = el.offsetWidth;
		elU.style.height = el.offsetHeight;
		elU.style.top = el.style.top;
		elU.style.left = el.style.left;
	}
}

function killUnder(menuID) {
	var el = document.getElementById(menuID + "_under");
	el.style.display = "none";
}