$(document).ready(function() {
	$("#divDestinationMap .pin").hover(
			function (e) {
				var text = this.name;
				var cityName = this.id;
				var x = e.pageX;
				var y = e.pageY;
				$("#mapCalloutDest").html(text);
				$("#mapCalloutDest").attr("href", '/travel/destinationDetails.html?cityName=' + cityName);
				var pixelsFromLeft = parseInt(($(this).css("left")));
				if (pixelsFromLeft > 240) {
					$("#divMapCallout").css({left: (x - 229), top: (y + 2)});
					$('#divMapCalloutWrapper').css({background:"url('/images/travel/callout2.png') no-repeat"});
					if (jQuery.browser.msie && (jQuery.browser.version < 7)) {
						$('#divMapCalloutWrapper').css({background:"url('/images/travel/callout2.gif') no-repeat"});
					}
				} else {
					$("#divMapCallout").css({left: (x - 12), top: (y + 2)});
					$('#divMapCalloutWrapper').css({background:"url('/images/travel/callout2_mirror.png') no-repeat"});
					if (jQuery.browser.msie && (jQuery.browser.version < 7)) {
						$('#divMapCalloutWrapper').css({background:"url('/images/travel/callout2_mirror.gif') no-repeat"});
					}
				}
				$("#divMapCallout").show();
				hideShowSelects("divMapCallout");

				// prevent the onclick event from reaching the map image and hiding the popup
				if (e.stopPropagation) {
					e.stopPropagation();
				}
			},

			function() {
				$("#divMapCallout").hide();
			}
	);

	$("#divMapCallout").hover (
			function() {
				$("#divMapCallout").show();
				$("#divMapCallout").css("cursor", "pointer");
				$("#mapCalloutDest").css("text-decoration", "underline");
			},

			function() {
				$("#divMapCallout").hide();
			}
	);

	$("#divMapCallout").click (function () {
		var link = $("#mapCalloutDest").attr("href");
		window.location = link;
	});

	$("#divDestinationMap .pin").click (function () {
		var destinatonDetailsUrl = '/travel/destinationDetails.html?cityName=' + this.id;
		window.location = destinatonDetailsUrl;
	});

	// hide the popup when the user clicks on the map
	$("#divDestinationMap").click(function () {
		hideMapCallout();
	});

	// make sure an image appears on page onload
	$("#divDestinationMap").css({ "background-image": "url(/images/travel/destination_map.jpg)" });

	// Get the By Region + All destination tabs acting like tabs
	function switchTabs(switch_to) {
		$('#divSelectMap span').removeClass('selected');
		$('#' + switch_to).addClass("selected");
	}

	$('ul.area_locations li a').click(function() {
		switchTabs('spnChooseByRegion');
	});

	$('#spnChooseAllDestinations a').click(function() {
		switchTabs('spnChooseAllDestinations');
	});
	$('#spnChooseByRegion a').click(function() {
		switchTabs('spnChooseByRegion');
	});
	$('#divMiniMap map area').click(function() {
		switchTabs('spnChooseByRegion');
	});

	$('#nationalPositions').show();

	if (location.hash != '' && location.hash != '#nationalView' && location.hash != '#mapView' && location.hash != '#listView') {
		switchTabs('spnChooseByRegion');
	};

});



