﻿common = {
    init: function() {

        if (!document.getElementsByTagName) return;
        if (!document.getElementById) return;

        common.fixIEHover("primaryNav");
        common.fixIEHover("secondaryNav");

        //popup links
        var links = document.getElementsByTagName("a");
        for (var i = 0; i < links.length; i++) {
            if (links[i].className.indexOf("popup") >= 0 || links[i].className.indexOf("Popup") >= 0) {
                links[i].onclick = function() {
                    tools.openWindow(this.href, "newWindow", "left=50,top=50,height=500,width=450,resizable,scrollbars=yes");
                    return false;
                }
            }
        }
    },

    fixIEHover: function(idName) {
        var navContainer = document.getElementById(idName);
        if (navContainer == null)
            return;
        navContainer = navContainer.firstChild;
        if (navContainer != null) {
            var navList;
            for (var i = 0; i < navContainer.childNodes.length; i++) {
                navList = navContainer.childNodes[i].firstChild;
                common.fixList(navList);
            }

        }
    },
    fixList: function(list) {
        var node;
        if (list != null) {
            for (var i = 0; i < list.childNodes.length; i++) {
                node = list.childNodes[i];
                if (node.nodeName == "LI") {
                    node.onmouseover = function() {
                        this.className += " over";
                    }
                    node.onmouseout = function() {
                        this.className = this.className.replace('over', "");
                    }
                    for (var j = 0; j < node.childNodes.length; j++) {
                        if (node.childNodes[j].nodeName == "UL")
                            common.fixList(node.childNodes[j]);
                    }
                }
            }
        }
    }
}
tools.addEvent(window, 'load', common.init);
