﻿var activesubmenu, activesubsubmenu;
activesubmenu = null;
activesubsubmenu = null;

window.onload = function () {
    // target top level navs
    var tlNav = document.getElementById("mainMenuContainer").childNodes;
    for (var tn = 0; tn < tlNav.length; tn++) {
        if (tlNav[tn].nodeName === "UL") {
            // scrub through all the child nodes
            var tlnavitems = tlNav[tn].childNodes;
            for (var tlni = 0; tlni < tlnavitems.length; tlni++) {
                if (tlnavitems[tlni].nodeName === "LI") {
                    // first check if there is a nested UL
                    var tlnism = tlnavitems[tlni].getElementsByTagName("UL")
                    if (tlnism.length > 0) {
                        // yes - set this LI to show the submenu onmouseover
                        tlnavitems[tlni].onmouseover = function () {
                            if (activesubmenu != null) {
                                activesubmenu.style.display = "none";
                                activesubmenu = null;
                            }
                            this.getElementsByTagName("UL")[0].style.display = "block";
                            activesubmenu = this.getElementsByTagName("UL")[0];
                        }
                        // next, go into the sub menu and check for children and nested UL's
                        var smnavitems = tlnism[0].childNodes;
                        for (var smni = 0; smni < smnavitems.length; smni++) {
                            if (smnavitems[smni].nodeName === "LI") {
                                // first check if there is a nested UL
                                var smnism = smnavitems[smni].getElementsByTagName("UL")
                                if (smnism.length > 0) {
                                    smnavitems[smni].onmouseover = function () {
                                        if (activesubsubmenu != null) {
                                            activesubsubmenu.style.display = "none";
                                            activesubsubmenu = null;
                                        }
                                        this.getElementsByTagName("UL")[0].style.display = "block";
                                        this.getElementsByTagName("UL")[0].onmouseout = function () {
                                            this.style.display = "none";
                                        }
                                        activesubsubmenu = this.getElementsByTagName("UL")[0];
                                    }
                                } else {
                                    smnavitems[smni].onmouseover = function () {
                                        if (activesubsubmenu != null) {
                                            activesubsubmenu.style.display = "none";
                                            activesubsubmenu = null;
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        tlnavitems[tlni].onmouseover = function () {
                            if (activesubmenu != null) {
                                activesubmenu.style.display = "none";
                                activesubmenu = null;
                            }
                        }
                    }
                } else {
                    continue;
                }
            }
        } else {
            continue;
        }
    }
};

