var lastShown = null;
$(document).ready(function(){
	// IE 6
	$('#menu .menuItem').mouseenter( function(){
		$(this).addClass('hover');

		if($(this).find('.submenu').length)
			{
			if(lastShown && (lastShown.parent().attr('id') == $(this).find('.submenu').parent().attr('id')))
				{
				return;
				}

			if(lastShown)
				lastShown.slideUp();

			var width = $(this).find('.submenu').width();
			var pos = $(this).position();
			$(this).find('.submenu').css({'marginLeft' : '-' + width + 'px', 'top' : pos.top + 'px'}).slideDown();

			lastShown = $(this).find('.submenu');
			}
		}).mouseleave( function(){
			$(this).removeClass('hover');
		});

	$('#menu .submenu').mouseleave(function(){
			$(this).slideUp();
			lastShown = null;
		});
	$('#menu').mouseleave(function(){
		$('.submenu').hide();
		lastShown = null;
		});

	});

