//
// jquery.map.js
// Copyright (c) Connect Group Ltd. All rights reserved.
// jQuery code for highlighting areas on a map.
//
// $Id: jquery.map.js 210 2009-10-15 09:33:59Z paul $
//

var defaultMapImageSrc = '';

$(document).ready(function() {
	defaultMapImageSrc = $("div#region-select-block img").attr("src");

	$("div#region-select-block map area").mouseover(function() {
		var region = $(this).attr("id");
		highlightRegion(region);
	});

	$("div#region-select-block map area").mouseleave(function() {
		$("div.left-content img").attr("src", defaultMapImageSrc);
		resetSelectedLinks();
	})	

	$("div#region-select-block ul li a").each(function() {
		var region = $(this).attr("class");
		$(this).hover(
			function() { highlightRegion(region); },
			function() { $("div.left-content img").attr("src", defaultMapImageSrc); resetSelectedLinks(); }
		);
	});
});

//
// getRegionImageSrc(region)
// Gets the location of the image with the specified region highlighted.
// PARAMS
//  region: the region to be highlighted.
// RETURNS
//  The location of the image with the specified region highlighted.
//
function getRegionImageSrc(region) {
	var indexOf = defaultMapImageSrc.indexOf(".jpg");
	return defaultMapImageSrc.substring(0, indexOf) + "-" + region + ".jpg";
}
//
// highlightRegion(region)
// Highlights the specified region on the map and selects the associated hyperlink.
// PARAMS
//  region: the region to be highlighted.
//
function highlightRegion(region) {
	resetSelectedLinks();
	$("div.left-content img").attr("src", getRegionImageSrc(region));
	$("div#region-select-block ul li a[class='" + region + "']").addClass("selected");
}
//
// resetSelectedLinks()
// Removes the "selected" class from all links associated with the map.
//
function resetSelectedLinks() {
	$("div#region-select-block ul li a").removeClass("selected");
};
