﻿doMenu = function() {
    iWidth = (navigator.appName.indexOf("Microsoft") != -1)
	       ? document.body.offsetWidth
		   : window.innerWidth;
    posLeft = ((iWidth - 900) / 2) + 'px';

    // position active menu
    if (document.getElementById('active')) {
        activeMenu = document.getElementById('active');
        activeMenu.childNodes[2].style.left = posLeft;
        activeMenu.className += ' show';
    }

    rootMenu = document.getElementById('main');
    for (i = 0; i < rootMenu.childNodes.length; i++) {
        node = rootMenu.childNodes[i];
        if (node.nodeName == 'LI') {
            node.onmouseover = function() {
                if (document.getElementById('active')) {
                    activeMenu.className = activeMenu.className.replace('show', '');
                }

                this.className += ' show';

                if (this.childNodes[2]) {
                    if (this.childNodes[2].nodeName == 'UL') {
                        this.childNodes[2].style.left = posLeft;
                    }
                }
            }
            node.onmouseout = function() {
                this.className = this.className.replace('show', '');

                if (document.getElementById('active')) {
                    activeMenu.className += ' show';
                }
            }
        }
    }
}

window.onload = doMenu;
window.onresize = doMenu;

