
; (function($)
{

    $.menu = function(options)
    {
        return $.menu.impl.init(this, options);
    };
    $.fn.menu = function(options)
    {
        return $.menu.impl.init(this, options);
    };

    $.menu.defaults =
    {
        delay: 1000
    };

    $.menu.impl = {
        menus: null,
        opts: {},
        init: function(menu, opt)
        {
            var self = this;
            self.menus = menu;
            self.option(opt);
            self.bindevent();
            
            var submenus = self.menus.find('li:has(ul)');
            if (submenus)
            {
                $.each(submenus, function(i, sub)
                {
                    self.hide($(sub));
                });
            }
        },

        option: function(opt)
        {
            this.opts = $.extend({}, this.opts, opt); ;
        },

        bindevent: function()
        {
            var self = this;
            self.menus.find('li').hover(function()
            {
                $(this).addClass("hover");

            },
		    function()
		    {
		        $(this).removeClass("hover");
		    });

            self.menus.find('li:has(ul)').hover(function()
            {
                self.show($(this));                

            },
		    function()
            {
		        self.hide($(this));
		    });
        },

        hide: function(item)
        {
            var self = this;
            if (!item) return;
            item.data('hide', true);
            if (item.data('hide'))
            {
                item.find('> ul').css('display', 'none'); // 可以将词句换成动画效果
                
                
            }
            self.opts.delay ? setTimeout(self.hide, self.opts.delay)
						    : self.hide();
        },

        show: function(item)
        {
            if (!item) return;
            item.data('hide', false);
            var style =
            {
                display: 'block',
                position: 'absolute'
            };

            item.find('> ul').css(style); // 可以将词句换成动画效果
    }


};
})(jQuery);

