//
// Custom Overlays source: http://code.google.com/apis/maps/documentation/overlays.html#Custom_Icons
//
function initialize() {
  if (GBrowserIsCompatible()) {
	var map = new GMap2(document.getElementById("map_canvas"));
	//GEOcoding source: http://code.google.com/apis/maps/documentation/services.html#Geocoding
	var geocoder = new GClientGeocoder();
	
	function showCenter(address, text) {
	  geocoder.getLatLng(
		address,
		function(point) {
		  if (!point) {
			alert(address + " not found");
		  } else {
			map.setCenter(point, 16);
			var marker = new GMarker(point);
			map.addOverlay(marker);
			//marker.openInfoWindowHtml(text);
			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml(text);
		    });
		  }
		}
	  );
	}

	function showAddress(address, index, text) {
	  //alert("ShowAddress" + address + "," + index);
	  geocoder.getLatLng(
		address,
		function(point) {
		  if (!point) {
			alert(address + " not found");
		  } else {
			map.addOverlay(createMarker(point, index, text));
		  }
		}
	  );
	}


//map.setCenter(new GLatLng(37.4419, -122.1419), 13);	// Googleplex
	//map.addControl(new GSmallMapControl());
	//map.addControl(new GMapTypeControl());
	
	map.setUIToDefault();

	// Create a base icon for all of our markers that specifies the
	// shadow, icon dimensions, etc.
	var baseIcon = new GIcon(G_DEFAULT_ICON);
	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);

	// Creates a marker whose info window displays the letter corresponding
	// to the given index.
	function createMarker(point, index, text) {
	  // Create a lettered icon for this point using our icon class
	  var letter = String.fromCharCode("A".charCodeAt(0) + index);
	  var letteredIcon = new GIcon(baseIcon);
	  letteredIcon.image = "http://www.google.com/mapfiles/marker" + index + ".png";

	  // Set up our GMarkerOptions object
	  markerOptions = { icon:letteredIcon };
	  var marker = new GMarker(point, markerOptions);

	  GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(text);
	  });
	  return marker;
	}
	
	var address = set_arr[1];	//Kemplex
	var kemtext = set_arr[2];	
	//map.setCenter(new GLatLng(51.525834,-0.082633), 16);
	showCenter(address, kemtext);
	showAddress(address, 'K', kemtext);
	
	for (var i=0;i<neigh_arr.length;++i) {
		showAddress(neigh_arr[i][2],neigh_arr[i][0],neigh_arr[i][3]);
	}

  } else alert ("Incompatible browser");
}

