	if (GBrowserIsCompatible()) {
    	var side_bar_html = "";
		var gmarkers = [];
      	var htmls = [];
      	var to_htmls = [];
      	var from_htmls = [];
	  	var geo;

		var iconParking = new GIcon();
		iconParking.image = "../images/parking-icon.png";
		iconParking.iconSize = new GSize(25, 25);
		iconParking.iconAnchor = new GPoint(12, 12);
		iconParking.infoWindowAnchor = new GPoint(20, 8);
	
  	   // sets up the parking marker and the event window
		function createMarker(point,name,html) {
  		var marker = new GMarker(point, {icon: iconParking});

      	var i = gmarkers.length;

     	//  "to here" form open
        to_htmls[i] = html + '<br>Directions: <b>To here<\/b> - <a href="javascript:fromhere(' + i + ')">From here<\/a>' +
           '<br>Start address:<form action="javascript:getDirections()">' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT"><br>' +
           'Walk <input type="checkbox" name="walk" id="walk" /> &nbsp; Avoid Highways <input type="checkbox" name="highways" id="highways" />' +
           '<input type="hidden" id="daddr" value="'+name+"@"+ point.lat() + ',' + point.lng() + 
           '"/>';
      	//  "from here" form open
        from_htmls[i] = html + '<br>Directions: <a href="javascript:tohere(' + i + ')">To here<\/a> - <b>From here<\/b>' +
           '<br>End address:<form action="javascript:getDirections()">' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT"><br>' +
           'Walk <input type="checkbox" name="walk" id="walk" /> &nbsp; Avoid Highways <input type="checkbox" name="highways" id="highways" />' +
           '<input type="hidden" id="saddr" value="'+name+"@"+ point.lat() + ',' + point.lng() +
           '"/>';
      	// The inactive version of the direction info
        html = html + '<br>Directions: <a href="javascript:tohere('+i+')">To here<\/a> - <a href="javascript:fromhere('+i+')">From here<\/a>';

        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        // save the info we need to use later for the side_bar
        gmarkers.push(marker);
        htmls[i] = html;
        // add a line to the side_bar html
        side_bar_html += '<a href="javascript:myclick(' + i + ')">' + name + '<\/a><br>';
        return marker;
      	}

      	// request the directions 
      	function getDirections() {
        // walking is fun and highways scare me
        var opts = {};
        if (document.getElementById("walk").checked) {
           opts.travelMode = G_TRAVEL_MODE_WALKING;
        }
        if (document.getElementById("highways").checked) {
           opts.avoidHighways = true;
        }
        // where do we begin and where do we go
        var saddr = document.getElementById("saddr").value
        var daddr = document.getElementById("daddr").value
        gdir.load("from: "+saddr+" to: "+daddr, opts);
      	}

	
      	// This function picks up the click and opens the corresponding info window
      	function myclick(i) {
        gmarkers[i].openInfoWindowHtml(htmls[i]);
      	}

     	// functions that open the directions forms
      	function tohere(i) {
        gmarkers[i].openInfoWindowHtml(to_htmls[i]);
      	}
      	function fromhere(i) {
        gmarkers[i].openInfoWindowHtml(from_htmls[i]);
      	}


      	// create the map
      	var map = new GMap2(document.getElementById("map"));
      	map.setCenter(new GLatLng(30.410798, -87.213570), 16);
	    
		// ground overlay
        var boundaries = new GLatLngBounds(new GLatLng(30.401288,-87.225047), new GLatLng(30.417898,-87.203563));
        var oldmap = new GGroundOverlay("../inc/dpmd_overlay2.png", boundaries);
    map.addControl(new GSmallMapControl());

        map.addOverlay(oldmap);

	    // for the directions 
        var gdir=new GDirections(map, document.getElementById("directions"));
	  
        // for placing search marker
        geo = new GClientGeocoder(); 

    	// list of words to be standardized 
        var standards = [   ["road","rd"],   
                        ["street","st"], 
                        ["avenue","ave"], 
                        ["av","ave"], 
                        ["drive","dr"],
                        ["saint","st"], 
                        ["north","n"],   
                        ["south","s"],    
                        ["east","e"], 
                        ["west","w"],
                        ["expressway","expy"],
                        ["parkway","pkwy"],
                        ["terrace","ter"],
                        ["turnpike","tpke"],
                        ["highway","hwy"],
                        ["lane","ln"]
                        ];

  	    // convert words to standard versions 
    	function standardize(a) {
      	for (var i=0; i<standards.length; i++) {
        if (a == standards[i][0])  {a = standards[i][1];}
      	}
      	return a;
    	}

    	// check if two addresses are sufficiently different and elimanate from choices 
    	function different(a,b) {
     	// only interested in the bit before the first comma in the reply
     		 var c = b.split(",");
     		 b = c[0];
     	    // convert to lower case
      		a = a.toLowerCase();
     		b = b.toLowerCase();
    		// remove apostrophies
    	 	a = a.replace(/'/g ,"");
 		    b = b.replace(/'/g ,"");
 		    // replace all other punctuation with spaces
 		    a = a.replace(/\W/g," ");
    		b = b.replace(/\W/g," ");
   		    // replace all multiple spaces with a single space
   		    a = a.replace(/\s+/g," ");
   		    b = b.replace(/\s+/g," ");
    		// split into words
   		    awords = a.split(" ");
      		bwords = b.split(" ");
            // perform the comparison
      		var reply = false;
      	for (var i=0; i<bwords.length; i++) {
        if (standardize(awords[i]) != standardize(bwords[i])) {reply = true}
     	}
      	return (reply);
    	}

        // place marker upon user reponse 
        function place(lat,lng) {
        var point = new GLatLng(lat,lng);
        map.setCenter(point,16); 
        map.addOverlay(new GMarker(point));
        document.getElementById("message").innerHTML = "";
        }

        //  Geocoding 
        function showAddress() {
        var search = document.getElementById("search").value;
        // Perform the Geocoding         
        geo.getLocations(search, function (result)
          {
              if (result.Status.code == G_GEO_SUCCESS) {
              // If there was more than one result, "ask did you mean" on them all 
              if (result.Placemark.length > 1) { 
                document.getElementById("message").innerHTML = "Did you mean:";
                // Loop through the results
                for (var i=0; i<result.Placemark.length; i++) {
                  var p = result.Placemark[i].Point.coordinates;
                  document.getElementById("message").innerHTML += "<br>"+(i+1)+": <a href='javascript:place(" +p[1]+","+p[0]+")'>"+ result.Placemark[i].address+"<\/a>";
                }
              }
              // If there was a single marker, is the returned address significantly different 
              else {
                document.getElementById("message").innerHTML = "";
                if (different(search, result.Placemark[0].address)) {
                  document.getElementById("message").innerHTML = "Did you mean: ";
                  var p = result.Placemark[0].Point.coordinates;
                  document.getElementById("message").innerHTML += "<a href='javascript:place(" +p[1]+","+p[0]+")'>"+ result.Placemark[0].address+"<\/a>";
                } else {
                  var p = result.Placemark[0].Point.coordinates;
                  place(p[1],p[0]);
                  document.getElementById("message").innerHTML = "Located: "+result.Placemark[0].address;
                }
              }
            }
            // Decode the error status 
            else {
              var reason="Code "+result.Status.code;
              if (reasons[result.Status.code]) {
                reason = reasons[result.Status.code]
              } 
              alert('Could not find "'+search+ '" ' + reason);
            }
          }
        );
      }




      // Reasons for failure, other than Chuck Close is now doing AOL commercials
      var reasons=[];
      reasons[G_GEO_SUCCESS]            = "Success";
      reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
      reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
      reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
      reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
      reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
      reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";
      reasons[G_GEO_BAD_REQUEST]        = "A directions request could not be successfully parsed.";
      reasons[G_GEO_MISSING_QUERY]      = "No query was specified in the input.";
      reasons[G_GEO_UNKNOWN_DIRECTIONS] = "The GDirections object could not compute directions between the points.";

      // catch directions errors
      GEvent.addListener(gdir, "error", function() {
        var code = gdir.getStatus().code;
        var reason="Code "+code;
        if (reasons[code]) {
          reason = reasons[code]
        } 

        alert("Failed to obtain directions, "+reason);
      });



      // Read the data from garages.xml
      var request = GXmlHttp.create();
      request.open("GET", "garages.xml", true);
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          var xmlDoc = GXml.parse(request.responseText);
          // obtain the array of markers and loop through it
          var markers = xmlDoc.documentElement.getElementsByTagName("marker");
          
          for (var i = 0; i < markers.length; i++) {
            // obtain the attribues of each marker
            var lat = parseFloat(markers[i].getAttribute("lat"));
            var lng = parseFloat(markers[i].getAttribute("lng"));
            var point = new GLatLng(lat,lng);
            var html = markers[i].getAttribute("html");
            var label = markers[i].getAttribute("label");
            // create the marker
            var marker = createMarker(point,label,html);
            map.addOverlay(marker);
          }
          // put the assembled side_bar_html contents into the side_bar div
          document.getElementById("side_bar").innerHTML = side_bar_html;
        }
      }
      request.send(null);
    }

    else {
      alert("Oops, the Interactive Map is not compatible with this browser");
    }


