/**
 * Drop Down Menu.
 * Version: 1.0
 *
 * The use of this script is strictly forbidden without prior written
 * consent. You must obtain permission before copying, modifying, 
 * redistributing, deriving or selling any part of this program.
 *
 * Copyright (C) 2009 HYPERZOID
 * All Rights Reserved
 */


// The Drop Down Menu object.
var dropDownMenu = null;


/**
 * Initializes this program.
 */
function initDropDownMenu() {

    dropDownMenu = new DropDownMenu();

}

/**
 * The constructor.
 */
function DropDownMenu() {

    // Number of milliseconds to wait before hiding a submenu.
    this.interval = 400;

    // Timer for triggering hide submenu events.
    this.timer = null;

    // DOM object of the currently opened menu box.
    this.current = null;
}


/**
 * Hides a drop down menu box.
 */
DropDownMenu.prototype.hide = function(domId) {

    dropDownMenu.timer = setTimeout('dropDownMenu.show("' + domId + '", false)',
                                    this.interval);

}


/**
 * Shows a drop down menu box.
 */
DropDownMenu.prototype.show = function(domId, isVisible) {

    menuBox = document.getElementById(domId);

    if (isVisible) {

        if (this.timer != null) {

            clearTimeout(this.timer);

        }

        if (this.current != null && this.current != menuBox) {
        
            this.current.style.visibility = "hidden";

        }
        this.current = menuBox;

        menuBox.style.visibility = "visible";

    } else {

        this.current = null;

        menuBox.style.visibility = "hidden";

    }

}


// Run this function upon the onload event.
addOnLoad(initDropDownMenu);