﻿
function TopNavigationReset(hoverId) {
    if (window.TopNavigationHoverId == hoverId) {
        TopNavigationSetHovering(window.TopNavigationSelected, window.TopNavigationSelectedChild);
    }
}

function TopNavigationHover(index, childIndex, hoverId) {
    if (window.TopNavigationHoverId == hoverId) {
        TopNavigationSetHovering(index, childIndex);
    }
}

function TopNavigationDelayReset() {
    var hoverId = TopNavigationGenerateId();
    window.TopNavigationHoverId = hoverId;
    setTimeout("TopNavigationReset(" + hoverId + ")", 1000);
}

function TopNavigationKeepHover() {
    var hoverId = TopNavigationGenerateId();
    window.TopNavigationHoverId = hoverId;
}

function TopNavigationDelayHover(index, childIndex) {
    var hoverId = TopNavigationGenerateId();
    window.TopNavigationHoverId = hoverId;

    if (!childIndex) {
        setTimeout("TopNavigationHover(" + index + ", " + childIndex + ", " + hoverId + ")", 150);
    }
    else {
        TopNavigationHover(index, childIndex, hoverId);
    }
}

function TopNavigationSetHovering(index, childIndex) {
    var counter = 1;
    var link = document.getElementById("TopNavigationLink" + counter);
    var sub = document.getElementById("TopNavigationSub" + counter);

    while (link) {
        if (link.className == "selected") {
            window.TopNavigationSelected = counter;
            var childCounter = 1;
            var selectedChildListItem = document.getElementById("TopNavigationChild" + counter + "_" + childCounter);
            while (selectedChildListItem) {
                if (selectedChildListItem.className == "selected") {
                    window.TopNavigationSelectedChild = childCounter;
                }
                childCounter++;
                selectedChildListItem = document.getElementById("TopNavigationChild" + counter + "_" + childCounter);
            }
        }
        link.className = (counter == index) ? "hover" : "";
        if (sub && sub.style) {
            sub.style.display = (counter == index) ? "block" : "none";
        }
        counter++;
        link = document.getElementById("TopNavigationLink" + counter);
        sub = document.getElementById("TopNavigationSub" + counter);
    }

    var counter = 1;
    var childListItem = document.getElementById("TopNavigationChild" + index + "_" + counter);

    while (childListItem) {
        childListItem.className = (counter == childIndex) ? "hover" : "";
        counter++;
        childListItem = document.getElementById("TopNavigationChild" + index + "_" + counter);
    }
}

function TopNavigationGenerateId() {
    if (!window.TopNavigationGeneratedId || window.TopNavigationGeneratedId > 1000){
        window.TopNavigationGeneratedId = 1;
    }
    else{
        window.TopNavigationGeneratedId++;
    }
    return window.TopNavigationGeneratedId;
}
