function Menu(element) {
    this.element = $(element);
    this.block = false;
    this.trigger = '';

    this.init = function() {
        var menu = this;
        this.element.mouseStay({handler: function() {
            if(!menu.block) {
                menu.block = true;
                menu.open();
            } else {
                menu.trigger = 'open';
            }
        }, delayTime: 200});
        this.element.mouseleave(function() {
            if(!menu.block) {
                menu.block = true;
                menu.close();
            } else {
                menu.trigger = 'close';
            }
        });
    };

    this.open = function() {
        var menu = this;

        this.element.find('.sub').slideDown(500, function() {
            menu.block = false;
            if (menu.trigger == 'close') {
                menu.close();
            }
            menu.trigger = '';
        });
    };

    this.close = function() {
        var menu = this;

        this.element.find('.sub').slideUp(500, function() {
            menu.block = false;
            if (menu.trigger == 'open') {
                menu.open();
            }
            menu.trigger = '';
        });
    };

    this.init();
}
