﻿
var topMenu = {
    currentItem: null,
    currentSubMenu: null,
    openingTimer: null,
    closingTimer: null,
    menuOpenTimeOut: 250,
    menuCloseTimeOut: 500,
    onItemOver: function(obj)
    {
        this.clearTimer();

        if (obj != this.currentItem)
        {
            this.clearSelection();
            this.currentItem = obj;

            this.openingTimer = setTimeout("topMenu.setSelection()", this.menuOpenTimeOut);
        }

    },
    onItemOut: function()
    {
        clearTimeout(this.openingTimer);
        this.closingTimer = setTimeout("topMenu.clearSelection()", this.menuCloseTimeOut);

    },
    setSelection: function()
    {
        this.currentSubMenu = this.currentItem.parentNode.getElementsByTagName("ul")[0]

        if (this.currentSubMenu)
        {
            this.currentSubMenu.style.display = "block";

            if (this.currentItem && this.currentItem.className != "current")
                this.currentItem.className = "selected";
        }
    },
    clearSelection: function()
    {
        if (this.currentItem && this.currentItem.className != "current")
            this.currentItem.className = "";

        if (this.currentSubMenu)
            this.currentSubMenu.style.display = "none";

        this.currentItem = null;
        this.currentSubMenu = null;
    },
    clearTimer: function()
    {
        clearTimeout(this.closingTimer);
        clearTimeout(this.openingTimer);
    },
    onMenuOver: function()
    {
        this.clearTimer();
    }
}


