﻿window.onload=function()
{	
	addOverState("nav");
}

var timeout = 4000;
var handler;

function addOverState(id) {
    if (!document.getElementById(id)) return false;

    var arrLi = document.getElementById(id).getElementsByTagName("LI");
    for (var i = 0; i < arrLi.length; i++) {
        if (arrLi[i].innerHTML == "") {
            arrLi[i].parentNode.removeChild(arrLi[i]);
        }
        arrLi[i].id = id + "_" + i;
        arrLi[i].onmouseover = function() {
            if (handler != null) {
                window.clearTimeout(handler);
            }
            if (this.parentNode.className != "") {
                out(this.parentNode.className);
            }
            this.parentNode.className = this.id;
            if (this.className.search("over") < 0) {
                this.className += " over";
            }
            if (this.className.search("fix") < 0) {
                this.className += " fix";
            }

        };

        arrLi[i].onmouseout = function() {
            this.className = this.className.replace("fix", "");
            handler = window.setTimeout("out('" + this.id + "');", timeout);
        };

        if (arrLi[i].parentNode.parentNode.nodeName != "LI") { //First Level
            arrLi[i].onclick = function() {
                if (this.className.search("fix")) {
                    if (handler != null) {

                    }
                    this.className = this.className.replace("fix", "");
                    handler = window.setTimeout("out('" + this.id + "');", timeout);
                } else {

                    if (this.className.search("fix") < 0) {
                        this.className += " fix";
                    }
                }
            };
        }
    }
    var arrUl = document.getElementById(id).getElementsByTagName("UL");
    for (i = 0; i < arrUl.length; i++) {
        if (arrUl[i].innerHTML == "") {
            arrUl[i].parentNode.removeChild(arrUl[i]);
        }
        if (arrUl[i].parentNode.nodeName == "LI") {
            arrUl[i].onmouseover = function() {
            
                if (this.parentNode.className.search("fix") < 0) {
                    this.parentNode.className += " fix";
                }
            };
            arrUl[i].onmouseout = function() {
                this.parentNode.className = this.parentNode.className.replace("fix", "");
                handler = window.setTimeout("out('" + this.parentNode.id + "');", timeout);
            };
        }
    }
}

function out(n) {
    var node = document.getElementById(n);
    if (node.className.search("fix") < 0) {
        node.className = node.className.replace("over", "");
        if (node.parentNode.className != "") {
            node.parentNode.className == "";
        }
    }
    
}

function outN(n, s) {
    var node = document.getElementById(n);
    node.className = node.className.replace("fix", "");
}