jQuery.fn.dropmenu = function(options) {
    var options = jQuery.extend({
        show: 0,
        hide: 0,
        delay: 500
    }, options);
    
    return this.each(function(){
        var $menuContainer = $(this);

        $menuContainer.find('.dDMLi').hover(function() { // mouse over LI
            $menuContainer.stopTime('dDMTO');
            var ulo = $(this).children('.dDMUl:first');
            if (ulo.length) {
                ulo.get(0).overFlag = true
                if ($(this).parent().parent().attr('id') == $menuContainer.attr('id')) { // 1 level
                    ulo.css({
                        top: $(this).height()
                    });
                }
                else { // 2+ level
                    ulo.css({
                        visibility: 'visible',
                        left: $(this).width()
                    });
                }
                if (ulo.queue().length) {
                    ulo.stop(true, true);
                    ulo.show();
                }
                else 
                    if (ulo.is(':hidden')) {
                        if (options.show) {
                            ulo.slideDown(options.show);
                        }
                        else {
                            ulo.show();
                        }
                    }
            }
            $('.dDMUl .dDMUl').each(function() {
                if (!this.overFlag && $(this).is(':visible')) {
                    if (options.hide) {
                        $(this).slideUp(options.hide);
                    }
                    else {
                        $(this).hide();
                    }
                }
            });
        }, function() { // mouse out LI
            var ulo = $(this).children('.dDMUl:first');
            if (ulo.length) {
                ulo.get(0).overFlag = false
            }
            var funcCloseSubMenu = function () {
                $('.dDMUl .dDMUl').each(function() {
                    if (!this.overFlag && $(this).is(':visible')) {
                        if (options.hide) {
                            $(this).slideUp(options.hide);
                        }
                        else {
                            $(this).hide();
                        }
                    }
                });
            }
            if (options.delay === false) {
                funcCloseSubMenu();
            }
            else {
                $menuContainer.oneTime(options.delay, 'dDMTO', funcCloseSubMenu);
            }
        });
    });
}



