var map;
var bounds;
var rideIcon;

function initialize() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(37.4419, -122.1419), 13);
    map.setUIToDefault();

    rideIcon = new GIcon(G_DEFAULT_ICON);
    rideIcon.iconSize = new GSize(20, 20);
    rideIcon.shadow = null;
    rideIcon.iconAnchor = new GPoint(10, 10);
    rideIcon.image = "/rideicon.png";
  }
}

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

  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(popupText);
  });
  return marker;
}

function addMarkers(markerArray) {
  for(var i = 0; i < markerArray.length; ++i) {
    var point = new GLatLng(markerArray[i][0], markerArray[i][1]);
	if(bounds == null) {
	  bounds = new GLatLngBounds();
	}
	bounds.extend(point);
	map.addOverlay(createMarker(point, markerArray[i][2]));
  }
}

function showTrack() {
  map.addOverlay(encodedPolyline);
  var bounds = encodedPolyline.getBounds();
  map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
  map.setMapType(G_PHYSICAL_MAP);
	  
  var theIcon = new GIcon(G_DEFAULT_ICON);
  theIcon.iconSize = new GSize(19, 19);
  theIcon.shadow = null;
  theIcon.iconAnchor = new GPoint(10, 10);
  theIcon.image = "/parkingicon.png";
  markerOptions = { icon:theIcon };
  var marker = new GMarker(encodedPolyline.getVertex(0), markerOptions);
  map.addOverlay(marker);
}
