function centerMap() // centers the map vertically if necessary
{
	var y = $("#footer").offset().top;
	if (y > 601)
	{
		$(".map_slider_wrapper").css("margin-top", ((y - 601)/2)+"px");
	}
}

// Runs when the DOM has been loaded
$(document).ready(function() {
	// Check if map exists
	if($('#map'))
	{
		// Loop through each AREA in the imagemap
		$('#map area').each(function() {
	
			// Assigning an action to the mouseover event
			$(this).mouseover(function(e) {
				var country_id = $(this).attr('id').replace('area_', '');
				$('#'+country_id).show();
			});
			
			// Assigning an action to the mouseout event
			$(this).mouseout(function(e) {
				var country_id = $(this).attr('id').replace('area_', '');
				$('#'+country_id).hide();
			});
			
			// Assigning an action to the click event
			$(this).click(function(e) {
				$(".country_info").hide();
				var country = $(this).attr('id').replace('area_', '');
				$("#info_"+country).show();
				$(".map_slider_wrapper .map_slider").animate({left: -905}, 500);
				return false;
			});
		});
		
		$(".back_to_map").click(function() {
			$(".map_slider_wrapper .map_slider").animate({left: 0}, 500);
			return false;
		});
		
		// vertically center the map (if necessary);
		centerMap();
		$(window).resize(centerMap);
		
		// map fading (to imply that the message will disappear when the map is clicked)
		if (!$.browser.msie || !($.browser.version.substring(0,1)<9))
		{
			$("#map").css("opacity", 0.7);
			$("#mission_dismiss").mouseenter(function(){ $("#map").stop().animate({opacity: 1}, 300); }).mouseleave(function(){ $("#map").stop().animate({opacity: 0.7}, 300); });
		}
		
		$("#mission_dismiss").click(function(){
			$(this).hide().unbind();
			if (!$.browser.msie || !($.browser.version.substring(0,1)<9)) $("#map").css("opacity", 1);
			$('#mission').fadeOut();
			return false;
		});
	}
});
