/*

	 Script: map.js
	 
	 Copyright: Fishnet NewMedia (c) 2004
	 
	 Create: 09/25/04
	 
	 Version: 1
	 
	 Compatibility: JavaScript 1.2
	 
	 Scripts: none
	 
	 Changes:
	 10/11/04 SCD - removed onmousemove event handler set by InitMap() 
	 
	 Description:

*/

var loc_ids = new Array();
var reg_exp = /loc_([0-9]+)/;
var offset_x = 5;
var offset_y = 45;

function MapSupported(){
	// Parse the navigator object for browser 
	// type and platform for compatibility.
	// Supported browsers include MSIE version 
	// 5+ and Netscape with Gecko version 1+.
	// Return the supported browser's initial.
	
	var useragent = navigator.userAgent;		// user agent string for the current browser.
	var browser = navigator.appName;			// official name of the current browser
	var platform = navigator.platform;			// platform on which the current browser is running
	var product = navigator.product;			// product name of the current browser
	var productsub = navigator.productSub;		// build number of the current browser
	
	if (product == "Gecko" && Number(productsub) > 20020605){
		// supported browser - Netscape
		return "N";
	}
	else if (browser == "Microsoft Internet Explorer" && document.getElementById) {
		if (platform.substring(0,3) == "MacPPC"){
			if(/MSIE ([0-9\.]+)/.test(useragent) && Number(RegExp.$1) >= 5.1){
				 // supported browser - MSIE
				 return "M";
			}
			else{
				 // unsupported browser
				 return "";
			}
		}
		else{
			// supported browser - MSIE
			return "M";
		}
	}
	else {
		// unsupported browser
		return "";
	}
}

function InitMap() {
	// Set up the onmousemove event handler for the each area object 
	// to track the x/y coordinates of the mouse in relation to the 
	// browser window object. Create a list of numberic location ids.
	var mapObj = document.getElementById("map");
	var areasObj = mapObj.getElementsByTagName("area");
	for (var i = 0; i < areasObj.length; i++){
		if (areasObj[i]){
			if (N){
				// Register the document object to capture all specified events.
				if (areasObj[i].captureEvents){
					areasObj[i].captureEvents(Event.MOUSEOVER | Event.MOUSEOUT | Event.CLICK);
				}
			}
			// Initialize the document object's onmousemove event handler.
			areasObj[i].onmouseover = MapShowLoc;
			areasObj[i].onmouseout = MapHideLoc;
			areasObj[i].onclick = MapOpenLoc;
			// Add the area's numberic id to the location ids array.
			var area_id = areasObj[i].getAttribute("id");
			if (area_id && reg_exp.test(area_id)){
				// Append the numberic id to the locations array.
				// Avoid using push() - not support by all browsers.
				loc_ids[loc_ids.length] = Number(RegExp.$1);
			}
		} 
	}
}

function MapMoveLoc(evnt) {
	// The argument "evnt" is the event object for the event.
	// The event object contains properties that describe a 
	// javascript event, and is passed as an argument to an 
	// event handler when the event occurs.	
	if (MapSupported() == "M") {
		if (window.event.srcElement.id && reg_exp.test(window.event.srcElement.id)){			
			// Get the numeric id of the location.
			var loc_id = Number(RegExp.$1);
			// Update the placement of the location's DIV container.
			var locName = document.getElementById("LocName" + loc_id);
			if (locName && locName.style.visibility == "visible"){
				locName.style.pixelLeft = (window.event.clientX + document.body.scrollLeft) - offset_x;
				locName.style.pixelTop = (window.event.clientY + document.body.scrollTop) - offset_y;
			}
		}
	}
	else if (MapSupported() == "N") {		
		if (evnt.target.id && reg_exp.test(evnt.target.id)){			
			// Get the numeric id of the location.
			var loc_id = Number(RegExp.$1);
			// Update the placement of the location's DIV container.
			var locName = document.getElementById("LocName" + loc_id);
			if (locName && locName.style.visibility == "visible"){
				locName.style.left = evnt.pageX - offset_x;
				locName.style.top = evnt.pageY - offset_y;
			}
		}
	}
}

function MapShowLoc(evnt) {
	// The argument "evnt" is the event object for the event.
	// The event object contains properties that describe a 
	// javascript event, and is passed as an argument to an 
	// event handler when the event occurs.
	
	if (MapSupported() == "M") {
		if (window.event.srcElement.id && reg_exp.test(window.event.srcElement.id)){			
			// Get the numeric id of the location.
			var loc_id = Number(RegExp.$1);
			// Hide the location's name DIV container.
			var locDetail = document.getElementById("LocDetail" + loc_id);
			if (locDetail && locDetail.style.visibility == "hidden"){
				var locName = document.getElementById("LocName" + loc_id);
				if (locName){
					locName.style.pixelLeft = (window.event.clientX + document.body.scrollLeft) - offset_x;
					locName.style.pixelTop = (window.event.clientY + document.body.scrollTop) - offset_y;
					locName.style.visibility = "visible";
				}
			}
		}
	}
	else if (MapSupported() == "N") {
		if (evnt.target.id && reg_exp.test(evnt.target.id)){			
			// Get the numeric id of the location.
			var loc_id = Number(RegExp.$1);
			// Hide the location's name DIV container.
			var locDetail = document.getElementById("LocDetail" + loc_id);
			if (locDetail && locDetail.style.visibility == "hidden"){
				var locName = document.getElementById("LocName" + loc_id);
				if (locName){
					locName.style.left = evnt.pageX - offset_x;
					locName.style.top = evnt.pageY - offset_y;
					locName.style.visibility = "visible";
			  }
		  }
		}
	}
}

function MapHideLoc(evnt) {
	// The argument "evnt" is the event object for the event.
	// The event object contains properties that describe a 
	// javascript event, and is passed as an argument to an 
	// event handler when the event occurs.
	
	if (MapSupported() == "M") {
		if (window.event.srcElement.id && reg_exp.test(window.event.srcElement.id)){			
			// Get the numeric id of the location.
			var loc_id = Number(RegExp.$1);
			// Hide the location's name DIV container.
			var locDetail = document.getElementById("LocDetail" + loc_id);
			if (locDetail && locDetail.style.visibility != "visible"){
				var locName = document.getElementById("LocName" + loc_id);
				if (locName){
					locName.style.visibility = "hidden";
				}
			}
		}
	}
	else if (MapSupported() == "N") {
		if (evnt.target.id && reg_exp.test(evnt.target.id)){			
			// Get the numeric id of the location.
			var loc_id = Number(RegExp.$1);
			// Hide the location's name DIV container.
			var locDetail = document.getElementById("LocDetail" + loc_id);
			if (locDetail && locDetail.style.visibility != "visible"){
				var locName = document.getElementById("LocName" + loc_id);
				if (locName){
					locName.style.visibility = "hidden";
				}
			}
		}
	}
}

function MapOpenLoc(evnt) {
	// The argument "evnt" is the event object for the event.
	// The event object contains properties that describe a 
	// javascript event, and is passed as an argument to an 
	// event handler when the event occurs.
	
	// First close all open locations.
	for (var i = 0; i <= loc_ids.length; i++){
		MapCloseLoc(loc_ids[i])
	}
	
	if (MapSupported() == "M") {
		if (window.event.srcElement.id && reg_exp.test(window.event.srcElement.id)){			
			// Get the numeric id of the location.
			var loc_id = Number(RegExp.$1);
			// Hide the location's name DIV container.
			var locName = document.getElementById("LocName" + loc_id);
			if (locName && locName.style.visibility == "visible"){
				locName.style.visibility = "hidden";
			}
			// Open the location's detail DIV container.
			var locDetail = document.getElementById("LocDetail" + loc_id);
			if (locDetail && locDetail.style.visibility == "hidden"){
				locDetail.style.pixelLeft = (window.event.clientX + document.body.scrollLeft) - offset_x;
				locDetail.style.pixelTop = (window.event.clientY + document.body.scrollTop) - offset_y;
				locDetail.style.visibility = "visible";
			}
		}
	}
	else if (MapSupported() == "N") {
		if (evnt.target.id && reg_exp.test(evnt.target.id)){			
			// Get the numeric id of the location.
			var loc_id = Number(RegExp.$1);
			// Hide the location's name DIV container.
			var locName = document.getElementById("LocName" + loc_id);
			if (locName && locName.style.visibility == "visible"){
				locName.style.visibility = "hidden";
			}
			// Open the location's detail DIV container.
			var locDetail = document.getElementById("LocDetail" + loc_id);
			if (locDetail && locDetail.style.visibility == "hidden"){
				locDetail.style.left = evnt.pageX - offset_x;
				locDetail.style.top = evnt.pageY - offset_y;
				locDetail.style.visibility = "visible";
			}
		}
	}
}

function MapCloseLoc(loc_id) {
	// Close the location's detail DIV container.
	var locDetail = document.getElementById("LocDetail" + loc_id);
	if (locDetail && locDetail.style.visibility == "visible"){
		locDetail.style.visibility = "hidden";
	}
}
	



