// Parent functions

var divId
var lastDivId
var justWait

function showMe(showId) {
	if (lastDivId > '') {
		$(lastDivId).className = 'level3HideMe';
	}
	if (divId == null || showId == divId) {
		
		$(showId).className = 'level2ShowMe';
		killTimeMe();
		divId = showId
	}else if (divId != showMe) {
		$(showId).className = 'level2ShowMe';
		$(divId).className = 'level2HideMe';	
		divId = showId
		killTimeMe();
	}
}

function killTimeMe () {
	clearTimeout(justWait);
}	

function timeMe(Id) {
	divId = Id
	justWait = setTimeout ("hideMe()", 500);
}


function hideMe() {
	$(divId).className = 'level2HideMe';
}

//Child functions

var divIdSub
var lastDivIdSub
var justWaitSub

function showMeSub(showIdSub) {
	if (divIdSub == null || showIdSub == divIdSub) {
		$(showIdSub).className = 'level3ShowMe';
		killSubTimeMe();
		divIdSub = showIdSub
	}else if (divIdSub != showMeSub) {
		$(showIdSub).className = 'level3ShowMe';
		$(divIdSub).className = 'level3HideMe';	
		divIdSub = showIdSub;
		killSubTimeMe();
	}
}

function killSubTimeMe () {
	clearTimeout(justWaitSub);
}	

function subTimeMe(IdSub) {
	divIdSub = IdSub
	justWaitSub = setTimeout ("subHideMe()", 5);
}


function subHideMe() {
	lastDivId = divIdSub
	$(divIdSub).className = 'level3HideMe';
}

function subHideMe2(divKill) {
	$(divKill).className = 'level3HideMe';
}

function setActiveSubNav(s) {

    var subMenus = $("rightNav");
    for(var i = 0; i < subMenus.childNodes.length; i++) {
        var onNode = subMenus.childNodes[i]; //These should be level 4 menus
        var linkTag = getFirstChild(onNode); //if the firstchild is a link then we have a menu
        var subLinks = getNextSibling(onNode) //this will get the div next to the div that we are on.  if the class name is subTertiary then we have child menus
        var hasChildren = false;
        
        if(subLinks && subLinks.className === "subTertiary") {
            hasChildren = true;
        }
                        
        if(linkTag && linkTag.tagName === "A") {
            if(linkTag.href.toLowerCase().indexOf(s.toLowerCase()) >= 0) {
                var oDiv = onNode.className = hasChildren === true ? "level4ArrowActive" : "level2Active";
                var downLevelMenu = getFirstChild(subLinks);
                    if(downLevelMenu) {
                        downLevelMenu.className = "level5ShowMe";
                    }
                return;
            }
        }
        if(hasChildren) {
            setActiveFromChildMenu(subLinks, s);
        }
    }
}

function setActiveFromChildMenu(oNode, page) {
    if(!oNode) {
        return;
    }
    
    var oSubMenus = getFirstChild(oNode);
    
    var oOnDiv = getFirstChild(oSubMenus);
    
    while(oOnDiv) {
        var linkTag = getFirstChild(oOnDiv);
        if(linkTag && linkTag.tagName === "A") {
            if(linkTag.href.toLowerCase().indexOf(page.toLowerCase()) >= 0) {
                getPreviousSibling(oNode).className = "level4ArrowActive";
                oSubMenus.className = "level5ShowMe";
                oOnDiv.className = "level5Active";
                return;
            }
        }
        oOnDiv = getNextSibling(oOnDiv);
    }
   
}




