jQuery().ready(function() { $('.menu_top > li').each(function() { if($(this).children('div').length > 0) { var height = $(this).children('div').height(); var padding = parseInt($(this).children('div').css('padding-top')); var $div = $(this).children('div'); var mouseover = false; $div.css({ height: 0, padding: 0, 'border-top': 0, 'border-bottom': 0, 'z-index': 100 }); $(this).mouseenter(function() { mouseover = true; $div.stop().animate({ height: height, padding: padding + ' 0', 'border-top': '1px', 'border-bottom': '1px' }, 100).siblings('a').addClass('active'); }).mouseleave(function() { mouseover = false; setTimeout(function() { if(!mouseover) { $div.stop().animate({ height: 0, padding: 0, 'border-top': 0, 'border-bottom': 0 }, 100, function() { $(this).siblings('a').removeClass('active'); }); } }, 50); }); $(this).children('a').click(function() { return false; }); } }); });