(function () {

    jQuery.fn.nav = function () {
        this.each(function () {
            new Nav(this);
        });
    };


    var Nav = function (containerElement) {
        this.containerElement = jQuery(containerElement);
        this.containerElement.find('.item a.top').each(function (i) {
            var hideTimeout = null;
            var subnav = jQuery(this).parent().find('ul');
            var hoverIn = function (e) {
                clearTimeout(hideTimeout);
                subnav.show();
            }
            var hoverOut = function (e) {
                hideTimeout = setTimeout(function () {
                    subnav.hide();
                }, 200);
            }
            jQuery(this).hover(hoverIn, hoverOut);
            subnav.hover(hoverIn, hoverOut);
        });
    };


    jQuery(function () {
        jQuery('#menu_main').nav();
    });

})();


