var mapary = new Array();

GoogleMap.prototype.map;
GoogleMap.prototype.point;
GoogleMap.prototype.marker;
GoogleMap.prototype.strref;
GoogleMap.prototype.mapname;
GoogleMap.prototype.map_holder;
GoogleMap.prototype.longitude;
GoogleMap.prototype.latitude;
GoogleMap.prototype.address;
GoogleMap.prototype.city;
GoogleMap.prototype.state;
GoogleMap.prototype.zip;
GoogleMap.prototype.zoom;
GoogleMap.prototype.defaultInfoOpen;
GoogleMap.prototype.iconURL;
GoogleMap.prototype.iconHeight;
GoogleMap.prototype.iconWidth;

function initMap(tmap_holder,tmapname,tlongitude,tlatitude,taddress,tcity,tstate,tzip,tzoom,tdefaultInfoOpen,ticonURL,ticonHeight,ticonWidth)
{
	mapary[mapary.length] = new GoogleMap(tmapname, tmap_holder,tlongitude,tlatitude,taddress,tcity,tstate,tzip,tzoom,tdefaultInfoOpen,ticonURL,ticonHeight,ticonWidth);	
	//alert('Adding Map to Map Load Array ['+tmapname+']');
}

function GoogleMap(tmapname, tmap_holder,tlongitude,tlatitude,taddress,tcity,tstate,tzip,tzoom,tdefaultInfoOpen,ticonURL,ticonHeight,ticonWidth)
{
	this.strref = "";
	this.mapname = tmapname;
	this.map_holder = tmap_holder;
	this.longitude = tlongitude;
	this.latitude = tlatitude;
	this.address = taddress;
	this.city = tcity;
	this.state = tstate;
	this.zip = tzip;
	this.zoom = tzoom;
	this.defaultInfoOpen = tdefaultInfoOpen;
	this.iconURL = ticonURL;
	this.iconHeight = ticonHeight;
	this.iconWidth = ticonWidth;
	
}

function loadGoogleMaps()
{	
	//alert('loadGoogleMaps ['+mapary.length+']');
	for(i=0; i<mapary.length; i++)
	{
			
		var gm = mapary[i];
		gm.strref = "mapary[" + i + "]";
		
		gm.map = new GMap(document.getElementById(gm.map_holder));
		gm.map.mapindex = i;
		gm.point = new GPoint(gm.latitude, gm.longitude);
		if (gm.zoom == 0) gm.map.centerAndZoom(gm.point, gm.zoom);	
		else gm.map.centerAndZoom(gm.point, gm.zoom);	
		gm.map.addControl(new GSmallMapControl());
		
		
		if (gm.iconURL == "")
		{
			gm.marker = new GMarker(gm.point);
			gm.map.addOverlay(gm.marker);	
		}
		else
		{
			var icon = new GIcon();
			icon.image = gm.iconURL;
			icon.iconSize = new GSize(gm.iconWidth, gm.iconHeight);
			icon.iconAnchor = new GPoint(13, 17);
			icon.infoWindowAnchor = new GPoint(11, 0);     	
			gm.marker = new GMarker(gm.point, icon);
		}
		
		gm.marker.mapindex = i;
		
		GEvent.addListener(gm.marker, "click", function()
		{
			if(isNaN(this.mapindex)) this.mapindex = i;
			var infoBoxHtml = '<div style="color:#000000"><b>' +mapary[this.mapindex].mapname+ '</b><br />' +mapary[this.mapindex].address+ '<br />' +mapary[this.mapindex].city+ ', ' +mapary[this.mapindex].state+ ' ' +mapary[this.mapindex].zip+ '<br /><div onclick="javascript:' + mapary[this.mapindex].strref + '.GoogleInfoBoxLinkClick()">Click here for directions</div></div>';
			mapary[this.mapindex].marker.openInfoWindowHtml(infoBoxHtml);
		});
	
		gm.map.addOverlay(gm.marker);
				
		if (gm.defaultInfoOpen == "true")
		{
			GEvent.trigger(gm.marker, "click");
		}
		
	}

}

GoogleMap.prototype.GoogleInfoBoxGetDirections = function()
{
	var addr = this.address + "+" + this.city + "+" + this.state + "+" + this.zip;
	addr.replace(" ", "+");
	var winURL = "http://maps.google.com/maps?f=d&amp;hl=en&amp;saddr=" 
		+ document.getElementById("txtGoogleInfoBox").value 
		+ "&daddr=" + addr
		+ "&sll=" + this.longitude + "," + this.latitude + "&sspn=" + this.longitude + "," + this.latitude + "&ie=UTF8&om=1";
	window.open(winURL);
}

GoogleMap.prototype.GoogleInfoBoxLinkClick = function()
{
	var getDirectionsHtml = "<div><b>Enter your address</b><br />"
		+ "<input id='txtGoogleInfoBox' type='text' style='width:215px' /><br />"
		+ "<a href='javascript:" + this.strref + ".GoogleInfoBoxGetDirections()'>Get Directions</a></div>";
	this.marker.openInfoWindowHtml(getDirectionsHtml);
}
	  	  	

