var activeSecondNav;
var currentSecondNav;
var navTimeout;

setVisibility = function(dom,visibility) {
    if (dom != null) {
        dom.style.visibility = visibility;
    }
}

initNav = function() {
    var i,j;
    var a;
    
    var nav = document.getElementById("first-nav-holder");
	
    var firstUL = nav.getElementsByTagName("ul")[0];
    
    for (i=0;i<firstUL.childNodes.length;i++) {
        if (firstUL.childNodes[i].nodeName == "#text") {
            continue;
        }
    
        var firstLi = firstUL.childNodes[i];
        var secondUL = firstLi.getElementsByTagName("ul")[0];
        
        if (secondUL != null) {
            secondUL.style.left = (90 - firstLi.offsetLeft) + "px";
            
            if (firstLi.className.match(/AspNet-Menu-Selected|AspNet-Menu-ChildSelected/)) {
                activeSecondNav = secondUL;
                
                setVisibility(secondUL,"visible");
            }
            
            var secondNavLinks = secondUL.getElementsByTagName("a");
            for (j=0;j<secondNavLinks.length;j++) {
                a = secondNavLinks[j];
                a.onmouseover = function() {onSecondNavHover()};
                a.onmouseout = onNavHout;
            }
        }
        
        a = firstLi.getElementsByTagName("a")[0];
        if (a != null) {
            a.onmouseover = function() {onFirstNavHover(this)};
            a.onmouseout = onNavHout;
        }
    }
    
    //can fix the strange dispay problem in IE
    nav.style.display = "block";
}

onFirstNavHover = function(a) {
    clearTimeout(navTimeout);
    
    var ul = a.parentNode.getElementsByTagName("ul")[0];
    
    //has second nav
    if (ul != undefined){
        //rollover the current active node
        if (ul == activeSecondNav) {
            setVisibility(currentSecondNav,"hidden");
            
            setVisibility(activeSecondNav,"visible");
        }
        //rollover other node
        else {
            //the active node has second nav
           if (activeSecondNav != null) {
                setVisibility(activeSecondNav,"hidden");
                
                setVisibility(ul,"visible");
            }
            //the active node has no second nav
            else {
                setVisibility(currentSecondNav,"hidden");
                
                setVisibility(ul,"visible");
            }
        }
    }
    //no second nav
    else {
        setVisibility(activeSecondNav,"hidden");
        
        setVisibility(currentSecondNav,"hidden");
    }
    
    //store the current rollover second nav
    currentSecondNav = ul;
}

onSecondNavHover = function() {
    clearInterval(navTimeout);
}

onNavHout = function() {
    if (activeSecondNav != null) {
        navTimeout = setTimeout(function(){
            setVisibility(activeSecondNav,"visible");
            //activeSecondNav.style.visibility = "visible";
            
            if (activeSecondNav != currentSecondNav){
                setVisibility(currentSecondNav,"hidden");
            }
        },500);
    }
    else {
        navTimeout = setTimeout(function(){
            setVisibility(currentSecondNav,"hidden");
        },500);
    }
}

hideThirdNavItems = function() {

    var list = $$(".ThirdNav .AspNet-Menu-NonLink");
    
    for (var i=0;i<list.length;i++) {
        list[i].parentNode.style.display = "none";
    }
}
