lastHtml = "&nbsp;";
lastElementTurnedOn = null;
hideTimer = false;

function showSub(which) { // default
    showSubInner(which, false);
}


function showSubInner(which, skipCleanup) {
    defaultNav = document.getElementById("selectedNav");
    if (!skipCleanup) {
        hideSubInner(false); // clean up
    }
    lastElementTurnedOn = null;
    if (which != null && which != defaultNav) { // default is the one that shows always highlighted
        which.className = "on"; // highlight
        lastElementTurnedOn = which; // record to remove highlighting
        if (defaultNav != null)
            defaultNav.className = "";
    }
    try {
        whichParent = which.parentNode.className; // since these things are housed in divs, we want that class name
        document.getElementById("nav2").innerHTML = document.getElementById(whichParent + "Menu").innerHTML;
    } catch (e) {
    // no problem
    }
    cancelHide();
}

function hideSub() {
    lastHtml = document.getElementById("nav2").innerHTML;
    //hideTimer = setTimeout(hideSubAndShowDefaultSecondaryNav, 1000,true);
    hideTimer = setTimeout(function(){
        hideSubInner(true)
        }, 1000); // closures!

}

function hideSubInner(showDefaultSecondaryNav) {
    document.getElementById("nav2").innerHTML = "&nbsp;";
    if (lastElementTurnedOn) {
        lastElementTurnedOn.className = ""; // clear highlighting
    }
    defaultNav = document.getElementById("selectedNav");
    if (defaultNav == null)
        return;
    defaultNav.className = "on";

    if (showDefaultSecondaryNav)
        showSubInner(defaultNav,true);

}

function onContainer2Over() {
    //document.getElementById("nav2").innerHTML = lastHtml;
    cancelHide();
}

function onContainer2Out() {
    //hideTimer = setTimeout(hideSubInner, 1000,true);
    hideTimer = setTimeout(function(){
        hideSubInner(true)
        }, 1000); // closures!
}

function cancelHide() {
    if (hideTimer) {
        clearTimeout(hideTimer);
    }
}


function prepNav() {
    defaultNav = document.getElementById("selectedNav");
    showSubInner(defaultNav,true);
}

