﻿

/**
 * Creates a windows-like drop down menu for a link.
 */
function Menu(trigger_id, list_id) {
    this.trigger_id = trigger_id;
    this.list_id = list_id;
    this.trigger = $(trigger_id);
    this.list = $(list_id);

    this.delay = 1000;
    this.hider = null;

    if (this.list && this.trigger) {
        this.list.menu = this;
        this.trigger.menu = this;

        this.trigger.onmouseover = function() {
            this.menu.show();
        }

        this.trigger.onmouseout = function() {
            this.menu.hide();
        }

        this.list.onmouseover = function() {
            this.menu.show();
        }

        this.list.onmouseout = function() {
            this.menu.hide();
        }        
    }
}

Menu.prototype.show = function() {
    if (this.hider != null) {
        clearTimeout(this.hider);
    }
    this.list.style.display = 'block';
};

Menu.prototype.hide = function() {
    this.hider = setTimeout("$('" + this.trigger_id + "').menu._hide()", this.delay);
};

Menu.prototype._hide = function() {
    this.list.style.display = 'none';
};
