/**********************************************************************************************
	Region map JS
	Date: 16 November 2006
	Called from: /template/region_map.rm 
				- /display_includes/region_map.rm
**********************************************************************************************/

// shortcuts for convenience
var $D = YAHOO.util.Dom;
var $E = YAHOO.util.Event;
var $ = $D.get; // get element by ID

var thisParentID = 'region_map';
var thisAreaClass = 'region_area';
var thisImageID = 'map-image';


/**********/
/* EVENTS */
/**********/

// on load
$E.addListener(window,'load',initRegionMap);

function initRegionMap(){	

	//Add hover actions to areas
	var arr_areas = $D.getElementsByClassName(thisAreaClass, 'area', thisParentID);
	for (i=0; i< arr_areas.length; i++){
		$E.addListener($(arr_areas[i].id), 'mouseover', showAreaHover, $(arr_areas[i].id), true);
		$E.addListener($(arr_areas[i].id), 'mouseout', hideAreaHover, $(arr_areas[i].id), true);
	}
	
	//preload hover images (id of the map areas correspond to the filenames of their gifs)
	var arr_hoverImages = new Array();
	for (i=0; i< arr_areas.length; i++){
		arr_hoverImages[i] = document.createElement('img');
		arr_hoverImages[i].src = "/display_images/region_map/" + arr_areas[i].id + ".gif";
	}
		
}

/**************/
/* FUNCTIONS */
/**************/

function showAreaHover(e, obj){
	var thisMap = obj.id;
	//Load hover image (id of the map areas correspond to the filenames of their gifs)
	$(thisImageID).src = "/display_images/region_map/" + thisMap + ".gif";
	
	$E.stopEvent(e); //equiv of 'return false'
}
function hideAreaHover(e, obj){
	$(thisImageID).src = "/display_images/region_map/uk.gif";
	
	$E.stopEvent(e); //equiv of 'return false'
}