var map;
var point;
var marker;
var address;

function initMap(map_holder, location, a, marker)
{
	map = new GMap(document.getElementById(map_holder));
  address = a;
	var icon = new GIcon();
	icon.image = marker;
	icon.iconSize = new GSize(40, 57);
	icon.iconAnchor = new GPoint(40, 57);
	icon.infoWindowAnchor = new GPoint(20, 0);
				
	geocoder = new GClientGeocoder();
	geocoder.getLatLng(
		address, 
		function(point) {
        if (!point) {
          alert(address + " not found");
        } else {
          map.setCenter(point, 13);
          marker = new GMarker(point, icon);
          map.addOverlay(marker);
          //marker.openInfoWindowHtml(address);
					//map.centerAndZoom(new GPoint(point), 4);
					GEvent.addListener(marker, "click", function()
					{
						var infoBoxHtml = "<div><b>"+location+"</b><br />"+address+"<br /><a href='javascript:GoogleInfoBoxLinkClick()'>Click here</a> for directions</div>";
						marker.openInfoWindowHtml(infoBoxHtml);
					});
        }
      }
  );

	map.addControl(new GSmallMapControl());

}

function GoogleInfoBoxGetDirections()
{
	var start = document.getElementById("txtGoogleInfoBox").value;
	var winURL = "http://maps.google.com/maps?f=d&hl=en&saddr=" 
		+ start
		+ "&daddr="
		+ address;
	window.open(winURL);
}

function GoogleInfoBoxLinkClick()
{
	var getDirectionsHtml = "<div><b>Enter your address</b><br />"
		+ "<input id='txtGoogleInfoBox' type='text' style='width:215px' /><br />"
		+ "<a href='javascript:GoogleInfoBoxGetDirections()'>Get Directions</a></div>";
	marker.openInfoWindowHtml(getDirectionsHtml);
}