/*
 * Orginally Authored by: Dave Lindquist (http://www.gazingus.org)
 *				- implements an dropdown menu based on a HTML list
 * Modifications by: Bill Brown & Artie Fort (http://www.williamcbrown.com)
 * 				- Positioning based on parent element
 *				- Over state for section indicator
 *				- Hide menu script from IE versions less than 5.5
 */

var currentMenu = null;

if (!document.getElementById)
    document.getElementById = function() { return null; }

function initializeMenu(sectionName, sectionLit) {
    var menu = document.getElementById(sectionName + "Menu");
    var actuator = document.getElementById(sectionName + "Actuator");
	var anchorloc = document.getElementById(sectionName + "Anchor");
	var sectionlit = false
	var is = new Is(); //for browser sniffing
    
if (is.ie5||is.ie51) return;
	
    if (menu == null || actuator == null) return;

	if (sectionLit == sectionName) {
		anchorloc.className = "section_button_hover";
    }
	
	//if (window.opera) return; // I'm too tired

    actuator.onmouseover = function() {	
		this.showMenu()
		
		if (anchorloc.className == "section_button_hover") {
			sectionlit = true
		}
		else {
			anchorloc.className = "section_button_hover";
		}			
    }
	
	actuator.onmouseout = function() {
		menu.style.visibility = "hidden"
		if (!sectionlit) {
			anchorloc.className = "section_button_out";
		}
    }
  
    actuator.showMenu = function() {
		menu.style.left = DL_GetElementLeft(anchorloc) + "px";
        menu.style.top = DL_GetElementTop(anchorloc) + anchorloc.offsetHeight + "px";
        menu.style.visibility = "visible";
		currentMenu = menu;
    }

}

function DL_GetElementTop(eElement)
{
    if (!eElement && this)
    {
        eElement = this;
    }

    var nTopPos = eElement.offsetTop;
    var eParElement = eElement.offsetParent;
    while (eParElement != null)
    {
        nTopPos += eParElement.offsetTop;
        eParElement = eParElement.offsetParent;
    }
    return nTopPos;
}

function DL_GetElementLeft(eElementL)
{
    if (!eElementL && this)
    {
        eElementL = this;
    }

    var nTopPos = eElementL.offsetLeft;
    var eParElement = eElementL.offsetParent;
    while (eParElement != null)
    {
        nTopPos += eParElement.offsetLeft;
        eParElement = eParElement.offsetParent;
    }
    return nTopPos;
}

// Browser Sniffer
function Is() {
agent = navigator.userAgent.toLowerCase();
this.major = parseInt(navigator.appVersion);
this.minor = parseFloat(navigator.appVersion);
this.ns = ((agent.indexOf('mozilla') != -1) && ((agent.indexOf('spoofer') == -1) && (agent.indexOf('compatible') == -1)));
this.ns4 = (this.ns && (this.major == 4));
this.ns6 = (this.ns && (this.major >= 5));
this.ie = (agent.indexOf("msie") != -1);
this.ie3 = (this.ie && (this.major < 4));
this.ie4 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.0") == -1));
this.ie5 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.0") != -1));
this.ie51 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.01")!=-1) );
this.ie55 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.5") != -1));
this.ie6 = (this.ie && (agent.indexOf("msie 6.0")!=-1) );
}