var timeout = 0;
$(document).ready(function(){
    $('.menu').hover(
		function() {
			clearTimeout(window.timeout);
			currenMenu = $(this).context;
			//$(this).addClass("menu");
            $(this).css("background-color", "#FF0000");
            $(this).css("background-image", "none");
			$n = 0;
			$('.menu').each(function() {
				pos = $(this).position();
				$n++;
				$d = 0;
				if ($n>1) {
					$d=1;
				}
				$('#popup'+$n).css("left", parseInt(pos.left)+$d+"px");
				$('#popup'+$n).css("top", parseInt(pos.top)+22+"px");
				if (currenMenu == $(this).context) {
					$('#popup'+$n).slideDown();
				}
				else {
					$('#popup'+$n).slideUp('fast');
				}
			});
        },
		function() {
			$(this).css("background-color", "#555555");
            $('#currentmenu').css("background-color", "#FF0000");
			$('#currentmenu').css("background-image", "none");
			clearTimeout(window.timeout);
			window.timeout = setTimeout("hidePopups()", 3000);
        }
    );
	$('.submenupop').hover(
	    function() {
			clearTimeout(window.timeout);
		},
		function() {
            clearTimeout(window.timeout);
			window.timeout = setTimeout("hidePopups()", 3000);
        }
	);
	$('.sublevel').hover(
		function() {
            $(this).css("background-color", "#FF0000");
		},
		function() {
            $(this).css("background-color", "#555555");
        }
	);
});

function hidePopups() {
	$n = 0;
	$('.menu').each(function() {
		$n++;
		$('#popup'+$n).slideUp('fast');
	})
}
