var Maps = {};

document.observe('dom:loaded', function(){
  // hard-coded HTML for the overlay content
  Maps.infoWindowContent = "<strong>Get directions from:</strong><br/>";
  Maps.infoWindowContent += "<form onsubmit='getDirections(); return false;'>";
  Maps.infoWindowContent += "<input type='text' id='destination' name='destination' />";
  Maps.infoWindowContent += "<input type='submit' value='Go' /></form><br/><br/>";
  Maps.infoWindowContent += "to:<br/>400 Continental Blvd., 6th Floor<br/>El Segundo, California 90245";
  
  var theMap = $('map');
  if(theMap) {
    Maps.directionsPanel = $('directions_panel');
    Maps.mwOffice = new GLatLng(33.920638, -118.390287);

    if (GBrowserIsCompatible()) {
      Maps.map = new GMap2(document.getElementById("map"));
      Maps.map.setCenter(Maps.mwOffice, 13);
      Maps.map.openInfoWindow(Maps.mwOffice, Maps.infoWindowContent);
      Maps.map.setUIToDefault();
      
    }
  }
});

function getDirections() {
    var directions = new GDirections(Maps.map, Maps.directionsPanel);
    GEvent.addListener(directions, "error", handleErrors);
    var destination = $F('destination');
    $('directions_panel').update();
    directions.load("from: " + destination + " to: 400 Continental Blvd, El Segundo, CA");
  }

function handleErrors() {
    $('directions_panel').update("Sorry, we can't seem to find directions for you.  Please check your starting address and try again");
}