$(function () {
	var menu_timeout = null;
	var current_menu = null;
	var y_offset = 41;
	
	$("li.parentMenu", $("div.navMain")).hover(function () {
		// This is the mouseover event
		window.clearTimeout(menu_timeout);
		if (current_menu) current_menu.hide();

		var nav_item = $(".rollover img", this);
		var pos = nav_item.offset();
		var menu_name = nav_item.attr("name").match(/([A-Za-z0-9]*)$/)[0];
		current_menu = $("#menu_"+menu_name);

		var top = pos["top"]+y_offset;
		var left = pos["left"] + ((nav_x_offsets[menu_name]) ? nav_x_offsets[menu_name] : 0) + ((!$.browser.msie) ? 1 : 0);
		
		var viewport_width = $(document).width()
		
		if (current_menu.outerWidth() + left > viewport_width)
			left -= current_menu.outerWidth() + left - viewport_width + (($.browser.msie) ? 20 : 5);

		current_menu.css("top", top).css("left", left);
		current_menu.show();
	
	}, function () {
		// This is the mouseout event
		menu_timeout = window.setTimeout(function() {
			current_menu.hide();
		}, 100);
	
	});
	
	$("div.subMenu").hover(function() {
		// This is the mouseover event
		window.clearTimeout(menu_timeout);

	}, function () {
		// This is the mouseout event
		menu_timeout = window.setTimeout(function() {
			current_menu.hide();
		}, 100);
	
	});
});

