$(document).ready(function() {
	$("#tabmenu").children("li").each(function() {
		$(this).hover(function() {
			u = $(this).children("ul").eq(0);
			if($(u).length > 0) {
				$(u).show();
				
				if($.browser.msie && $.browser.version < 8) {
					$(".left").css("visibility", "hidden");
					$("#map").css("visibility", "hidden");
				}
				heig = $(u).height();
				$(u).children("li").each(function() {
					$(this).css("height", (heig) + "px");
				});
				$(u).find("li").each(function() {
					$(this).hover(function() {
						$(this).addClass("hover");
					}, function() {
						$(this).removeClass("hover");
					});
				});
			}
		}, function() {
			if($.browser.msie && $.browser.version < 8) {
				$(".left").css("visibility", "");
				$("#map").css("visibility", "");
			}
			$(this).children("ul").eq(0).hide();
		});
	});
	var activeLink = false;
	var activeMenu = false;
	var at = false;
	var bubble = false;
	$("a.showportal").click(function() {
		if(activeMenu) {
			$(activeLink).removeClass("hover");
			$(activeMenu).hide();
		}
		$(this).addClass("hover");
		activeLink = this;
		m = $(this).attr("rel");
		heig = $("#" + m).height();
		$("#" + m).children("li").each(function() {
			$(this).css("height", (heig) + "px");
			$(this).hover(function() {
				$(this).addClass("hover");
				clearTimeout(at)
			}, function() {
				$(this).removeClass("hover");
				clearTimeout(at)
				at = setTimeout(function() {
					if(activeMenu) {
						$(activeLink).removeClass("hover");
						$(activeMenu).hide();
					}
				}, 1000);
			});
		});
		$("#" + m).click(function(evt) {
			bubble = true;
		});
		$("#" + m).show();
		activeMenu = $("#" + m);
		return false;
	});
	$(document).click(function() {
		if(bubble) {
		} else {
			if(activeMenu) {
				$(activeLink).removeClass("hover");
				$(activeMenu).hide();
			}
		}
		bubble = false;
	});
	$(document).keyup(function(evt) {
		if (evt.keyCode == '27') {
			if(activeMenu) {
				$(activeMenu).hide();
			}
		}
	});
	
});
