$(document).ready(function()
{
	$("#mini_basket").hover(
									function()
									{
										if ($(this).height() == 20)
											$(this).addClass("round-bottom").animate({height:"53px"}, "fast");
									}, 
									function()
									{
										if ($(this).height() > 20)
										$(this).animate({height:"20px"}, "fast", function(){$(this).removeClass("round-bottom");});
									});

	$("#user").hover(
									function()
									{
										var height = $("li", this).length * 20;
										if ($(this).height() == 20)
											$(this).addClass("round-bottom").animate({height:(height+20)+"px"}, "fast");
									}, 
									function()
									{
										var height = $("li", this).length * 20;
										if ($(this).height() > 20)
											$(this).animate({height:"20px"}, "fast", function(){$(this).removeClass("round-bottom");});
									});
		
	var subMenus = new Array();
	var overMenu = -1;
	var currentMenu = null;
	var menuToHide = null;
	var hideTimer = 0;
	
	$(".nav-menu li").each(function(i){
		if ($(this).find("ul").length > 0)
		{
			subMenus[subMenus.length] = $(this);
			$(this).mouseenter(showMenu).mouseleave(doHideMenu)
		}
	});
		
	function getObjectIndexInArray(array, obj)
	{
		for (var count=0;count<array.length;count++)
		{
			if (array[count][0] == obj[0])
				return count;
		}
		return -1;
	}
	
	function doHideMenu()
	{
		overMenu = -1;
		menuToHide = $(this);
		$(this).find("ul").stop(true,true);

		hideTimer = setTimeout(hideMenu, 400);
	}
	
	function hideMenu()
	{
		hideTimer = 0;
		var thisMenu = getObjectIndexInArray(subMenus, menuToHide);
	
		if (currentMenu)
			currentMenu.find("ul").fadeOut("slow");
		currentMenu = null;
	}
	
	function showMenu()
	{
		if (hideTimer)
			clearTimeout(hideTimer);
		hideTimer = 0;
		$(this).find("ul").stop(true,true);
		var overMenu = getObjectIndexInArray(subMenus, $(this));
		currentMenu = $(this);
		$(this).find("ul").delay(400).fadeIn("fast");
	}
});
