(function ($) {
    $.fn.blaarghMenu = function() {
        var root  = $(this);
        var hoverTimer = null;
        var scrollTimer = null;

        $(this).find('ul').hide().end().find('li a').each(function() {
            var allMofoDropDowns = root.find('ul');
            var dropDown = $(this).next('ul');

            dropDown.css({
                '-moz-border-radius-bottomright': '10px',
                '-moz-border-radius-bottomleft': '10px',
                '-webkit-border-bottom-left-radius': '10px',
                '-webkit-border-bottom-right-radius': '10px'
            });

            $(this).mouseenter(function () {
                    hoverTimer = setTimeout(function () {
                        if (dropDown.is(':hidden'))
                            allMofoDropDowns.hide();

                        dropDown.slideDown({duration: 500, easing: 'easeOutExpo'});;
                    }, 200);
            });

            $(this).mouseleave(function() {
                if (hoverTimer) clearInterval(hoverTimer);
            });

            dropDown.mouseenter(function () {
                if (scrollTimer) clearInterval(scrollTimer);
            });

            dropDown.mouseleave(function () {
                scrollTimer = setTimeout(function() {
                    //dropDown.slideUp({duration: 400, easing: 'easeInBack'});
                    dropDown.hide();
                }, 200);
            });
        });
    }
})(jQuery);

$(function () {
    $('#menu').blaarghMenu();
});

