// all java script

  var map;
  var geocoder;
  var icon = new GIcon();
          icon.image = "http://labs.google.com/ridefinder/images/mm_20_green.png";
          icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
          icon.iconSize = new GSize(12, 20);
          icon.shadowSize = new GSize(22, 20);
          icon.iconAnchor = new GPoint(6, 20);
          icon.infoWindowAnchor = new GPoint(5, 1);

  // CapitalCitiesCache is a custom cache that extends the standard GeocodeCache.
  // We call apply(this) to invoke the parent's class constructor.
  function CapitalCitiesCache() {
    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.
  CapitalCitiesCache.prototype = new GGeocodeCache();

  // Override the reset method to populate the empty cache with
  // information from our array of geocode responses for capitals.
  CapitalCitiesCache.prototype.reset = function() {
    GGeocodeCache.prototype.reset.call(this);
    for (var i in city)
      this.put(city[i].name, city[i]);
  }

  function load(name, address)
  {
    map = new GMap2(document.getElementById("map"));
    map.enableDoubleClickZoom();
    map.enableContinuousZoom();
    map.addControl(new GMapTypeControl(),
        new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(70, 5)));
    map.addControl(new GLargeMapControl(),
    		new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10, 10)));
    map.addControl(new GOverviewMapControl());
    map.addControl(new GScaleControl(),
    		new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10, 125)));
    //var point = new GLatLng(41.996976, -91.630526);
    geocoder = new GClientGeocoder();
	geocoder.setCache(new CapitalCitiesCache());
    geocoder.getLatLng(address,  function (point)
    {
    	map.setCenter(point, 15);

		if(name == 'default')
		    var infoTabs = [
		    new GInfoWindowTab("Address", "<a href='http://crwash.org'>"
		                                  + "<b>Washington High School</b></a>"
		                                  + "<br>2205 Forest Dr SE "
		                                  + "<br>Cedar Rapids, IA 52403"
		                                  + "<br>(319) 558-2161"),
		    new GInfoWindowTab("Directions", "<center><form action='http://maps.google.com/maps' method='get' target='_blank'>"
		                                  + "To: <b>Washington High School</b>"
		                                  + "<br>From: <br><input type='text' name='saddr' id='saddr' onFocus='this.value=\"\"' value='Start Location'>"
		                                  + "<input type='submit' value='Get Directions'>"
		                                  + "<input type='hidden' name='daddr' value='" + point.lat() + "," + point.lng() + "'></form>")
		  ];
		else
		  var infoTabs = [
          new GInfoWindowTab("Address", "<b>" +name + "</b><br>" + address),
          new GInfoWindowTab("Directions", "<center><form action='http://maps.google.com/maps' method='get' target='_blank'>"
                                      + "To: <b>" + name + "</b>"
                                      + "<br>From: <br><input type='text' name='saddr' id='saddr' onFocus='this.value=\"\"' value='Sart Location'>"
                                      + "<input type='submit' value='Get Directions'>"
                                      + "<input type='hidden' name='daddr' value='" + point.lat() + "," + point.lng() + "'></form>")
      	  ];

	  var marker = new GMarker(point, icon);
	  GEvent.addListener(marker, "click", function() {
	    marker.openInfoWindowTabsHtml(infoTabs);
	  });
	  map.addOverlay(marker);
	  marker.openInfoWindowTabsHtml(infoTabs);


    })
  }

  function addAddressToMap(response)
  {
    map.clearOverlays();
    if (response && response.Status.code != 200)
      alert("Unable to locate " + decodeURIComponent(response.name));
    else
    {
      var place = response.Placemark[0];
      geocoder.getLatLng(place.Point,  function (point)
                      {
                        map.setCenter(point, 14);
          var infoTabs = [
          new GInfoWindowTab("Address", place.address),
          new GInfoWindowTab("Directions", "<center><form action='http://maps.google.com/maps' method='get' target='_blank'>"
                                      + "To: <b>" + response.name + "</b>"
                                      + "<br>From: <br><input type='text' name='saddr' id='saddr' onFocus='this.value=\"\"' value='Sart Location'>"
                                      + "<input type='submit' value='Get Directions'>"
                                      + "<input type='hidden' name='daddr' value='" + point.lat() + "," + point.lng() + "'></form>")
      ];
          var marker = new GMarker(point, icon);
          GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowTabsHtml(infoTabs);
          });
          map.addOverlay(marker);
          marker.openInfoWindowTabsHtml(infoTabs);
      })
    }
  }

function showAddress(address)
{
      if (geocoder)
      {
        geocoder.getLatLng(
          address,
          function(point)
          {
            if (!point)
              alert(address + " not found");
            else
            {
              map.setCenter(point, 15);
              var infoTabs = [
                  new GInfoWindowTab("Address", address),
                  new GInfoWindowTab("Directions", "<center><form action='http://maps.google.com/maps' method='get' target='_blank'>"
                                  + "To: <b>" + address + "</b>"
                                  + "<br>From: <br><input type='text' name='saddr' id='saddr' onFocus='this.value=\"\"' value='Sart Location'>"
                                  + "<input type='submit' value='Get Directions'>"
                                  + "<input type='hidden' name='daddr' value='" + point.lat() + "," + point.lng() + "'></form>")
  ];

              var marker = new GMarker(point, icon);
              map.addOverlay(marker);
              marker.openInfoWindowTabsHtml(infoTabs);
            }
          }
        );
      }
    }

  function findCity(which)
  {
    if (which != 0)
      geocoder.getLocations(city[which - 1].name, addAddressToMap);
  }

  function toggleDiv(div)
  {
    if(document.getElementById(div).style.display == "none")
      document.getElementById(div).style.display = "block";
    else
      document.getElementById(div).style.display = "none";
  }

  function hideAndShow(hide, show)
  {
	  document.getElementById(hide).style.display = 'none';
	  document.getElementById(show).style.display = 'block';
  }