var map = null;
var geocoder = null;

function load() {
  if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById("smMap"));
	map.setMapType(G_HYBRID_MAP);
	geocoder = new GClientGeocoder();
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
  }

  GEvent.addListener(map, "click", function(marker, point) {
	map.setCenter(point, 13);
  });
}

function showAddress(address, iconImg, zoomSize) {
  if (geocoder) {
	geocoder.getLatLng(
	  address,
	  function(point) {
		if (point) {
		  map.setCenter(point, zoomSize);
		  var icon = new GIcon(BaseIcon);
		  icon.image = iconImg;
		  icon.iconSize = new GSize(20, 34);
		  var marker = new GMarker(point, icon);
		  map.addOverlay(marker);
		}
	  }
	);
  }
}

function setMarker(address, markerNum) {
  if (geocoder) {
	geocoder.getLatLng(
	  address,
	  function(point) {
		if (point) {
		  var icon = new GIcon(BaseIcon);
		  icon.image = '/images/marker' + markerNum + '.png';
		  icon.iconSize = new GSize(20, 34);
		  var marker = new GMarker(point, icon);
		  map.addOverlay(marker);
		}
	  }
	);
  }
}

function setCenter(address, zoom) {
  if (geocoder) {
	geocoder.getLatLng(
	  address,
	  function(point) {
		if (point) {
		  map.setCenter(point, zoom);
		}
	  }
	);
  }
}

var BaseIcon = new GIcon();
BaseIcon.shadow = 'http://www.google.com/mapfiles/shadow50.png';
BaseIcon.iconSize = new GSize(20, 34);
BaseIcon.shadowSize = new GSize(37, 34);
BaseIcon.iconAnchor = new GPoint(9, 34);
BaseIcon.infoWindowAnchor = new GPoint(9, 2);
BaseIcon.infoShadowAnchor = new GPoint(18, 25);