var currDrop = "";
var currTimer;
function delay(cmd, time) {
/* function: delay()
 * Schedules execution of "cmd" "time" seconds in the future.
 * IN:  cmd is javascript (function or script) to call
 *      time is number of seconds to wait before executing cmd
 * OUT: none
 */
 	var seconds = time * 1000;
	currTimer = setTimeout(cmd, seconds);
}
function displaySub() {
/* function: displaySub()
 * This function is called ONMOUSEOVER
 * Sets an elements display attribute to block and sets up the hide function (after delay)
 * IN:  IMPLIED: The ID of the element this function is applied to must match the ID of the dropdown menu
 *      such that drop down ID = "dd_" + element ID
 * OUT: none
 */
	setLyr(this, "dd_" + this.id);
	if (currDrop != "") {
		document.getElementById(currDrop).style.display = "none";	
	}
	document.getElementById("dd_" + this.id).style.display = "block";
	document.getElementById("dd_" + this.id).onmouseover = killTimer;
	document.getElementById("dd_" + this.id).onmouseout = hideSub;
	currDrop = "dd_" + this.id;
}
function hideSub() {
/* function: hideSub()
 * This function is called ONMOUSEOUT
 * Calls the delay function for setting the display attribute to none one second from now.
 * IN:  IMPLIED: The HTML element to apply the hide
 * OUT: none
 */
	if (this.id.indexOf("dd_")) {
		delay("document.getElementById('dd_" + this.id + "').style.display = 'none'",1);
	} else {
		delay("document.getElementById('" + this.id + "').style.display = 'none'",1);
	}
}
function killTimer() {
/* function: killTimer()
 * If the user's mouse is in the dd menu, we need to kill the timer so that the dd menu doesn't disapear
 * IN:  Global currTimer
 * OUT: none
 */	
	clearTimeout(currTimer);
}
function initMenu() {
/* function: initMenu()
 * This function is called on the documents.ONLOAD.
 * Looks for the ID "navRow" and adds the onmouseover and onmouseout behaviors to each anchor tag within
 * IN:  none
 * OUT: none
 */	
 	if (document.getElementById("navRow")) {
		navElem = document.getElementById("navRow").getElementsByTagName("a");
		for(i=0;i<navElem.length;i++) {
			if (document.getElementById("dd_"+navElem[i].id)) {
				navElem[i].onmouseover = displaySub;
				navElem[i].onmouseout = hideSub;
			}
		}
	}
}

addEvent(window, "load", initMenu);

/* The follow code is from: 
 * http://www.quirksmode.org/js/findpos.html
 * Position the drop down menus under their main menu item
 */
 
var hide  = true;
function showhide(objTxt) {
	var x = new getObj(objTxt);
	hide = !hide;
	x.style.visibility = (hide) ? 'hidden' : 'visible';
}

function setLyr(obj,lyr) {
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	newY += 20;
	var x = new getObj(lyr);
	x.style.top = newY + 'px';
	x.style.left = newX + 'px';
}

// modified findPosX & findPosY based on: http://blog.firetree.net/2005/07/04/javascript-find-position/
function findPosX(obj) {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}


function getObj(name) {
	if (document.getElementById) {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	} else if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	} else if (document.layers) {
		if (document.layers[name]) {
			this.obj = document.layers[name];
			this.style = document.layers[name];
		} 
	}
}