$(document).ready(function($) {
	$("#Navbar li").hover(function() {
			
			// 移到
			var subnav = $(".submenu", $(this));
			if (subnav.size() == 0) return;
			
			var pos = $(".nav").position();
			pos = parseInt(pos.left);
			if (isNaN(pos)) pos = 0;
			
			var left = Math.round(pos + $(this).attr("offsetLeft"));
			var total = $("#Navbar").attr("offsetWidth");
			var length = Math.round(subnav.width());
			
			subnav.show();
			$(this).addClass("navhover");
			if (left + length > total) 
				subnav.css("right", "0px");
			else
				subnav.css("left", (left - pos) + "px");
		}, function() {
			
			// 移出
			$(".submenu", $(this)).hide();
			$(this).removeClass("navhover");
		});
});
