﻿window.onload = function() {
    if (document.all) addOverState("navigation");
    if (document.all) addOverState("product_navigation");
    addClickNavigation("product_navigation");
}

var timeout = 0;
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", "");
}

var selected = "";
function addClickNavigation(id) {
    var list = document.getElementById(id).getElementsByTagName("LI");
    for (var i = 0; i < list.length; i++) {
        if (list[i].parentNode.parentNode == document.getElementById(id)) {
            if (list[i].getElementsByTagName("UL").length > 0) {
                list[i].getElementsByTagName("UL")[0].id = "navi" + i;
                if (list[i].getElementsByTagName("UL")[0].style.display == "block") {
                    selected = "i" + i;
                }
            }
            list[i].id="i" + i;
            list[i].onclick = function() {
                if (selected != "") {
                    document.getElementById("nav" + selected).style.display = "";
                }
                if (document.getElementById("nav" + this.id) != null) {
                    document.getElementById("nav" + this.id).style.display = "block";
                    selected = this.id;
                }
            }
        }
    }
}