function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
    // start of the drop down script
    // this is a modified version of the Suckerfish Dropdown by Patrick Griffiths and Dan Webb
    // The other half of this is happening in the stylesheet
    
    navRoot = document.getElementById("nav");
    for (i=0; i<navRoot.childNodes.length; i++) {
        node = navRoot.childNodes[i];
        if (node.nodeName=="LI") {
        
            // Check for a dropdown. If yes, add arrow
            subnode  = node.getElementsByTagName("ul");
            if (subnode.length != 0) {
                for (j=0; j<subnode.length; j++) {
                    subnav = subnode[j];
                    // creating and adding the menu arrows
                    
                    toggleImage = document.createElement("img");
                    toggleImage.setAttribute("class", "navicon");
                    toggleImage.setAttribute("alt", "");
                    toggleImage.src = "/site_images/nav_arrow.gif";
                    node.insertBefore(toggleImage, node.firstChild);
                    
                }
            }
            
            // this adds the .over class to menus for browsers that don't get the CSS
            if (document.all&&document.getElementById) {
                node.onmouseover=function() {
                    this.className+=" over";
                }
                node.onmouseout=function() {
                    this.className=this.className.replace(" over", "");
                }
            }
        }
    }

})


addLoadEvent(function() {

    var expandMenu = document.getElementById("expandnav");
    for (i=0; i<expandMenu.childNodes.length; i++) {
        var theMenu = expandMenu.childNodes[i];
        if (theMenu.nodeName=="LI") {
            ul = theMenu.getElementsByTagName("ul");
            for (j=0; j<ul.length; j++) {
                subMenu = ul[j];
                subMenu.className = "toggleon";
                var newToggle = makeThing([i], theMenu);
                subMenu.setAttribute("id", "togglelist"+[i]);
            }
        }
    }
    
    
    function makeThing(thing1, thing2){
        var newThing = document.createElement("a");
        newThing.setAttribute("id", "togglelink"+thing1);
        newThing.setAttribute("href", "#");
        newThing.innerHTML = "[+]";
        thing2.insertBefore(newThing, thing2.firstChild);
        newThing.onclick = function (){
            doToggle(thing1);
        }
    }
    
    function doToggle(xxx){
        var linkID = "togglelink"+xxx;
        var listID = "togglelist"+xxx;
        toggleLink = document.getElementById(linkID);
        toggleList = document.getElementById(listID);
        if(toggleList.className == "toggleon"){
            toggleList.className = "toggleoff";
            toggleLink.innerHTML = "[-]";
        } else if(toggleList.className == "toggleoff"){
            toggleList.className = "toggleon";
            toggleLink.innerHTML = "[+]";
        }
    }


})