// Google maps wrapper
function mtiGMaps(_divMap, _divLoading)	{
//Constructor
	mapSetup();	//create map
//public:
	this.mapLoading = function (bShow) {
		_divLoading.style.display = (bShow == true) ? "block" : "none";
		_divLoading.style.visibility = (bShow == true) ? "visible" : "hidden";
	}
	
	this.plotArray = function (arrResults) {
		for (var i=0; i < arrResults.length; i++) {
			var webSiteURL;
			if (arrResults[i]['website'] == '') {
				webSiteURL = "#";
			} else {
				//todo: URL validation would be a good idea
				webSiteURL = "http://" + arrResults[i]['website'];
			}
			var ptHtmlLabel = "<div class='map_pt_label'><b>"	

			if (webSiteURL == "#")	{
				ptHtmlLabel = ptHtmlLabel + "<a style='color: black; text-decoration:underline;'>" + arrResults[i]['facility_name'] + "</a></b>";
			} else {
				ptHtmlLabel = ptHtmlLabel + "<a href='#' onclick='javascript:window.open(\""+ webSiteURL + "\")'>" + arrResults[i]['facility_name'] + "</a></b>";
			}

			ptHtmlLabel = ptHtmlLabel + "<br/>" +
				arrResults[i]['address'] + "<br/>" +
				arrResults[i]['city'] + ", MN" + " " + arrResults[i]['zipcode'] + "<br/>" +
				arrResults[i]['contact_first'] + " " + arrResults[i]['contact_last'] + " (" + arrResults[i]['email'] + ")<br/>" +
				"<b>SERVICES:</b>  " + arrResults[i]['services'] + "<br/></div>";
				
			addPoint(i, arrResults[i]['lat'], arrResults[i]['lon'], ptHtmlLabel);	
		}
	}
	
	this.showMarkerInfo = function(nIndex) {
		myMarkers[nIndex].openInfoWindowHtml(myLabels[nIndex]);
	}
	
	this.clearPoints = function () {
		myMap.clearOverlays();
		myLabels = new Array();
		myMarkers = new Array();
	}
	
//private:
	var myMap;
	var myMarkers = new Array();
	var myLabels = new Array();
	
	function addPoint(index, lat, lon, label) {
		var marker = new GMarker(new GLatLng(lat,lon));
		myMarkers[index] = marker;
		myLabels[index] = label;
		
		GEvent.addListener(marker, "click", 
			function () {
				marker.openInfoWindowHtml(label);
			});
		myMap.addOverlay(marker);
	}
	
	function mapSetup() {
		if (GBrowserIsCompatible()) {
			myMap = new GMap2(_divMap);
			myMap.setCenter(new GLatLng(46.535608,-93.608663), 6);	//center on MN
			myMap.addControl(new GSmallMapControl());
		}
		else {
			alert('gMaps.js error: Please upgrade your browser to latest version.');
		}
	}
}