﻿// global variables
var intNavItems = 0;
var objMenuActive = null;
var objNavActive = null;
var tmrMenu = null;
var tmrMenuDelay = null;

// initialization
window.onload = function() {
    // add link to logo
    var oLogo = document.getElementById("HeaderLogo");
    oLogo.onclick = function() {
        document.location.href = "index.html";
    };
    oLogo.onmouseout = function() {
        document.getElementById("HeaderLogo").style.backgroundPosition = "left";
    };
    oLogo.onmouseover = function() {
        document.getElementById("HeaderLogo").style.backgroundPosition = "right";
    };

    // set active navigation item
    var oNav = document.getElementById("Navigation");
    for (var i = 0; i < oNav.childNodes.length; i++)
        if (oNav.childNodes[i].className == "itemMenu") objNavActive = oNav.childNodes[i];

    // auto close menu
    document.onmousemove = function() {
        var e = window.event || arguments[0];
        var o = e.target || e.srcElement;

        while (o && o.tagName != "BODY") {
            var id = o.id;
            if (id && (id.indexOf("Menu") + id.indexOf("NavItem")) == -1) {
                if (tmrMenu) {
                    clearTimeout(tmrMenu);
                    tmrMenu = null;
                }
                return;
            }
            o = o.parentNode;
        }
        if (!tmrMenu) tmrMenu = setTimeout("menuOff()", 250);
    };
}

// expand layer
function expand(o) {
    var oExp = o.nextSibling; while (oExp.tagName != "DIV") oExp = oExp.nextSibling;
    var oArrow = o; while (oArrow.className.substr(0, 8) != "expander") oArrow = oArrow.previousSibling;
    oExp.style.display = oExp.style.display == "block" ? "none" : "block";
    if (oArrow.className.indexOf("Blue") > 0) {
        oArrow.className = oExp.style.display == "block" ? "expanderBlueOpen" : "expanderBlueClosed";
    } else {
        oArrow.className = oExp.style.display == "block" ? "expanderOpen" : "expanderClosed";
    }
}

// get menuObject
function menuObject(o) {
    return document.getElementById("Menu" + o.id.substr(7, 1));
}

// turn menu off
function menuOff() {
    if (objMenuActive != null) {
        var objMenu = menuObject(objMenuActive);
        if (objMenu) {
            if (tmrMenuDelay != null) { clearTimeout(tmrMenuDelay); tmrMenuDelay = null; }
            objMenu.style.display = "none";
        }
        if (objMenuActive != objNavActive) objMenuActive.className = "itemOut";
    }
    objMenuActive = null;
    return true;
}

// toggle menu on/off
function menuToggle(o, url) {
    if(url) document.location.href = url;
}

// navigation mouse over an mouse out
function navHighlight(o, b) {
    if (b) {
            menuOff();
            var objMenu = menuObject(o);
            if (objMenu) {
                if (tmrMenuDelay != null) { clearTimeout(tmrMenuDelay);tmrMenuDelay = null; }
                tmrMenuDelay = setTimeout(function() { objMenu.style.display = "block"; }, 300);
                o.style.cursor = "default";
            } else {
                o.style.cursor = "pointer";
            }
            objMenuActive = o;
            o.className = "itemMenu";
    }
}
