function navBuilder(test) {
    var NavBuilder = {};
    
    // build dropdown
    test.onmouseover = function() {
//alert(buttonHistory);
//alert(test.innerHTML);
	if (true == buttonHistory) {
		mouseOver();
	} else {
		inTimeOut = setTimeout(mouseOver, 100);
	}
    }
   
    function mouseOver() {
	buttonHistory = true;
        clearTimeout(outTimeOut);
        // loop through all buttons to set style back to not-hover
        for (var i=0; i<test.parentNode.childNodes.length; i++) {
            // make sure all extra buttons keep their class
            if ("nb_home" == test.className) { // if the button you hit was an extra
                if ("nb_home" == test.parentNode.childNodes[i].className) { //if any others are extras
                    test.parentNode.childNodes[i].className = "nb_home";
                } else { // for all non-extras change class to blank
                    test.parentNode.childNodes[i].className = "";
                }
                test.className = "nb_home";
            } else if ("nb_home" != test.parentNode.childNodes[i].className) { // set all links that aren't extra to blank class
                test.parentNode.childNodes[i].className = "";
                // set the activated button to hover state
                test.className = "nb_hover";
            }
        }
    }
    
     // on mouseout wait 1/2 sec until dropdown vanishes
    test.onmouseout = function() {
        outTimeOut = setTimeout(mouseOut, 500);
	clearTimeout(inTimeOut);
    }
    
    // remove dropdown
    function mouseOut() {
       	buttonHistory = false;
	if ("nb_home" != test.className) {
            test.className = "";
        }
    }
    return NavBuilder;
}
    var buttonHistory = false;
    var outTimeOut; // needs to wait 1 sec before closing
    var inTimeOut;


function triggerNav() {
    var mainNav = document.getElementById("main_nav");
    for (var i=0; i<mainNav.childNodes.length; i++) {
        if ("LI" == mainNav.childNodes[i].tagName) {
            var test = mainNav.childNodes[i];
            var newButton = new navBuilder(test);
        }
    }
}

triggerNav();
