var map;
var markerHash = {};

google.load("maps", "2.x");
google.setOnLoadCallback(initialize);

function initialize() {
  if (GBrowserIsCompatible()) {
    map = new google.maps.Map2(document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
    for (var i = 0; i < markers.length; i++) {
      var current = markers[i];
      marker = addMarker(current.id, current.latitude,current.longitude, current.description);
      markerHash[current.id] = {marker:marker, description:current.description, visible:true};
    }
  }
}

function focusPoint(id) {
  markerHash[id].marker.openInfoWindowHtml(markerHash[id].description);
}

// A function to create the marker and set up the event window
// function createMarker(point,name,html) {
function createMarker(point, html) {
	// FF 1.5 fix
  html = '<div style="white-space:nowrap;">' + html + '</div>';
  var marker = new GMarker(point);
  return marker;
}

function addMarker(id, latitude, longitude, description) {
		var point = new GLatLng(latitude, longitude)
    var marker = createMarker(point, description);
    GEvent.addListener(marker, 'click',
      function() {
        focusPoint(id);
      }
    );
    map.addOverlay(marker);
    return marker;
}
