var d = document;
var gDelayToggle = "on";
var myGlobalVar1 = null;
var myGlobalVar2 = null;
var gHideTimer = null; //global timer for the hide timeout
if (navigator.vendor == "Apple Computer, Inc." || navigator.platform == "MacPPC") {
    //if the user is running Safari or using a Mac, disable the javascript nav delay timer.
    //the delay timer works as intended on a PC, however it causes problems with the mouseover/out on Mac or Safari
    //gDelayToggle = "off";
}
function prepareNav(){
    if (!d.getElementById("snav")) 
        return false;
    if (!d.getElementsByTagName("DD")) 
        return false;
    var nav = d.getElementsByTagName("DD");
    for (var i = 0; i < nav.length; i++) {
        addNav(nav[i]);
    }
}
function addNav(whichnav){
    //this function will add the mouseover and mouseout events to the whichnav object
    if (whichnav.className == "nav" || whichnav.className == "nav_adj_left") {
        whichnav.onmouseover = function(){
            myGlobalVar1 = this;
            showNav(myGlobalVar1, 'show');
        }
        whichnav.onmouseout = function(){
            myGlobalVar1 = this;
            if (gDelayToggle == "off") {
                showNav(myGlobalVar1, 'hide');
            }
            else {
                gHideTimer = setTimeout("showNav(myGlobalVar1, 'hide')", 4000);
            }
        }
        //the first "dd" nav bar does not have the "nav" class and requires only the show mouseover event.
    }
    else 
        if (whichnav.className == "on") {
            whichnav.onmouseover = function(){
                myGlobalVar1 = this;
                showNav(myGlobalVar1, 'hide');
            }
        }
}
function showNav(whichnav, navtype){
    //this function toggles the nav to the specific object.
    //whichnav is the object, navtype is the toggle switch.  it can be either "show" or "hide"
    if (navtype == "show") {
        if (gHideTimer) { //if the hide timer is currently counting..
            clearTimeout(gHideTimer); //disable the hide timer
        }
        var list = whichnav.getElementsByTagName("UL");
        for (var i = 0; i < list.length; i++) {
            if (list[i].className == "nav_off") {
                clearNav();
                list[i].className = "nav_display";
                var nav = d.getElementsByTagName("UL");
                for (var j = 0; j < nav.length; j++) {
                    if (nav[j].className == "nav_current") {
                        nav[j].className = "nav_current_off";
                    }
                }
            }
        }
    }
    else 
        if (navtype == "hide") {
            if (!d.getElementById("snav")) 
                return false;
            if (!d.getElementsByTagName("UL")) 
                return false;
            var list = d.getElementById("snav").getElementsByTagName("DD");
            for (var i = 0; i < list.length; i++) {
                var nav = d.getElementsByTagName("UL");
                for (var j = 0; j < nav.length; j++) {
                    if (nav[j].className == "nav_current_off") {
                        nav[j].className = "nav_current";
                    }
                    else 
                        if (nav[j].className == "nav_display") {
                            nav[j].className = "nav_off";
                        }
                }
            }
        }
}
function clearNav(){
    //This function clears the navigation menu entirely.
    var list = d.getElementById("snav").getElementsByTagName("DD");
    for (var i = 0; i < list.length; i++) {
        if (list[i].className == "nav" || list[i].className == "nav_adj_left") {
            var lista = list[i].getElementsByTagName("UL");
            for (var j = 0; j < lista.length; j++) {
                lista[j].className = "nav_off";
            }
        }
    }
}

addLoadEvent(prepareNav);
