//<![CDATA[

function load() {
	var location = [
		{
			name: "McKenzie River Music",
			Status: {
				code: 200,
				request: "geocode"
			},
			Placemark: [
				{
					address: "455 W. 11th, Eugene, Oregon 97401",
					street: "455 W. 11th",
					city: "Eugene",
					state: "OR",
					zip: "97401",
					"AddressDetails": {
						"Country": {
							"CountryNameCode": "US",
							"AdministrativeArea": {
								"AdministrativeAreaName": "OR",
								"SubAdministrativeArea": {
									"SubAdministrativeAreaName": "Eugene",
									"Locality": {
										"LocalityName": "W. 11th",
										"Thoroughfare": {
											"ThoroughfareName": "455 W. 11th"
										},
										"PostalCode": {
											"PostalCodeNumber": "97401"
										}
									}
								}
							}
						},
						Accuracy: 4        
					},
					Point: {
						coordinates: [-123.099732, 44.047795, 0]
					}
				}
			]
		},
	];

  var map;
  var geocoder;

  // MRMCache is a custom cache that extends the standard GeocodeCache.
  // We call apply(this) to invoke the parent's class constructor.
  function MRMCache() {
    GGeocodeCache.apply(this);
  }

  // Assigns an instance of the parent class as a prototype of the
  // child class, to make sure that all methods defined on the parent
  // class can be directly invoked on the child class.
  MRMCache.prototype = new GGeocodeCache();

  // Override the reset method to populate the empty cache with
  // information from our array of geocode responses for capitals.
  MRMCache.prototype.reset = function() {
    GGeocodeCache.prototype.reset.call(this);
    for (var i in location) {
      this.put(location[i].name, location[i]);
    }
  }

  map = new GMap2(document.getElementById("map"));

  // Here we set the cache to use the UsCitiesCache custom cache.
  geocoder = new GClientGeocoder();
  geocoder.setCache(new MRMCache());

	// Add controls to map
	map.addControl(new GLargeMapControl());
	map.addControl(new GScaleControl(),new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(5, 40)));
	map.addControl(new GMenuMapTypeControl());
	map.addControl(new GOverviewMapControl());

	// Display location on map
  function addAddressToMap(response) {
    map.clearOverlays();

    if (response && response.Status.code != 200) {
      alert("Unable to locate " + decodeURIComponent(response.name));
    } else {
      var place = response.Placemark[0];
      var point = new GLatLng(place.Point.coordinates[1],
                              place.Point.coordinates[0]);
      var center = new GLatLng(place.Point.coordinates[1] - 100,
                              place.Point.coordinates[0] - 100);
      map.setCenter(center, 15);
      map.openInfoWindowHtml(point, "<strong>" + location[0].name
       + "</strong><br>" + place.street + "<br>" + place.city + ", " + place.state + "  " + place.zip);

			// Add marker
			var marker = new GMarker(point);
			map.addOverlay(marker);
			//marker.openInfoWindowHtml(address);
    }
  }

	geocoder.getLocations(location[0].name, addAddressToMap);
}

//]]>