// Functions and variables for the ServiceCentre map
//
// (c) 1999-2005 Bright Interactive Limited. All rights reserved.
// http://www.bright-interactive.com | info@bright-interactive.com
// Tel: 0870 240 6520


// What IDs (from the database) are the regions?
var min_region_id = 254;
var max_region_id = 297;

// These vars are used to store the curret state --
// are we over a menu or over the map
var over_menu = 0;
var over_map = 0;

// What delay before closing a menu? In milliseconds
var close_delay = 1500; // 2 seconds


var preloadFlag = false;
var maps = new Array();
for (var i = min_region_id; i <= max_region_id; i++) {
	maps[i] = newImage();
	maps[i].src = '/img/map/'+i+'.gif';
}


function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}


function showMap(id) {
	// The user has moved their mouse over a region of the map
	// so highlight the region and open its popup, closing any
	// other popups.
	
	// First check that the user is not over a menu -- this
	// should solve problem with PC IE
	if (over_menu) 
	{
		return;
	}

	document.getElementById('map_overlay').src='/img/map/' + id + '.gif';
	over_map = id;
	for (var i = min_region_id; i <= max_region_id; i++) {
		if (i == id) {
			showPopup('region' + i);
		}
		else {
			hidePopup('region' + i);
		}
	}
	
	// Hide the popup for the problem regions
	if (id==261 || id==260 || id==257 || id==255 || id==254) {
		hideRegionSelect();
	}
	
}

function hideMap(id) {
	// The user has moved their mouse off the map region, but they
	// might be over the menu (in which case over_menu is some
	// non-zero value)
	if (!over_menu) {
		over_map = 0;
		document.getElementById('map_overlay').src='/img/map/map_blank.gif';
		// Close the menu in a second (as long as the user doesn't
		// popup another one)
		setTimeout("checkHidePopup()",close_delay); 
	}
}


function overMenu(id) {
	// The user is over a menu -- make sure no other action closes it!
	//keep_popup_open = id;
	over_menu = id;
}


function offMenu(id) {
	// The user is now off the menu -- so check in a second if it needs
	// to be close
	//keep_popup_open = 0;
	over_menu = 0;
	setTimeout("checkHidePopup()",close_delay); 
}


function checkHidePopup() {
	// Close popups if the user isn't over a menu or map region
	if (!over_menu && !over_map) {
		for (var i = min_region_id; i <= max_region_id; i++) {
			hidePopup('region' + i);
		}
	}
}

function showPopup(id) {
	div = document.getElementById(id);
	if (div.style.visibility != 'visible' ) {
		div.style.visibility = 'visible';
	}
}

function hidePopup(id) {
	 
	div = document.getElementById(id);
	if (!div) return false;
	if (div.style.visibility != 'hidden' ) {
		div.style.visibility = 'hidden';
	}
	showRegionSelect();
}


// Hide or show the region select element because it always
// appears in front of popups on IE.

function hideRegionSelect() {
	document.getElementById('regionSelect').style.visibility = 'hidden';
}

function showRegionSelect() {
	document.getElementById('regionSelect').style.visibility = 'visible';
}
	
