//based on http://www.alistapart.com/articles/dropdowns/

// function called when user mouseovers menu item
// adds the "mouse_in" class name to the submenu so it will display it
function mouse_in() {
    this.className += "mouse_in";
}

// function called when user mouses out of menu item
// removes "mouse_in" class name from submenu so it will no longer be displayed
function mouse_out() {
    this.className = this.className.replace("mouse_in", " ");
}

function mouse_toggle() {
    if (this.className.search("mouse_in") == -1)
        this.className += "mouse_in";
    else
        this.className = this.className.replace("mouse_in", " ");
}

function getElementsByClassName(name) {
    var nodes = new Array();
    helper(document.body, nodes, name);
    return nodes;
}

function helper(elem, nodes, name) {
    for (var i = 0; i < elem.childNodes.length; i++) {
        if (elem.childNodes[i].className == name) {
            nodes.push(elem.childNodes[i]);
        }
        helper(elem.childNodes[i], nodes, name);
    }
}

// function to be called when the page loads.  Sets the two functions above to handle the
// mouseover and mouseout events repsectively for menu items.
// Gets the root element of the list (the top level ul tag) and loops through its decendants
// that are li tags, assigning the mouse in and out functions to them.
function start() {
    if (document.getElementById) {
        var menu_roots = new Array();
        menu_roots = getElementsByClassName("nav_list");
        menu_root = document.getElementById("nav_list");
        if (menu_root) {
            menu_roots.push(menu_root);
        }
        for (j = 0; j < menu_roots.length; j++) {
            list_elements = menu_roots[j].getElementsByTagName("li");
            for (i = 0; i < list_elements.length; i++) {
                node = list_elements[i];
                node.className = "";
                node.onclick = mouse_toggle;
                node.onmouseover = mouse_in;
                node.onmouseout = mouse_out;
                if (node.getElementsByTagName("ul").length != 0) {
                    a = node.getElementsByTagName("a")[0];
                    a.onclick = function () { return false; };
                }
            }
        }

        menu2 = document.getElementById("top_nav");
        if (menu2) {
            list2 = menu2.getElementsByTagName("li");
            for (i = 0; i < list2.length; i++) {
                node2 = list2[i];
                node2.onmouseover = mouse_in;
                node2.onmouseout = mouse_out;
                if (node2.getElementsByTagName("ul").length != 0) {
                    a = node2.getElementsByTagName("a")[0];
                    a.onclick = function () { return false; };
                }
            }
        }
    }
    if (window.BoxChanger) {
        bx = new window.BoxChanger();
    }
}


