    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;

    $(document).ready(function() {
      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map_canvas"));
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
		map.setUIToDefault();
		var point = new GLatLng(51.459462029964634, -0.9661531448364258);
		map.setCenter(point, 12);
		map.addOverlay(new GMarker(point));
		}
    });
    
    function setDirections(fromAddress) {
      gdir.load("from: " + fromAddress + " to: 1 Napier Ct, Napier Road, READING, UK",{"locale":"en_uk"});
    }

    function handleErrors(){
		$("#buttons").hide();
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     $("#directions").html("<br /><br />Sorry, we could not find this address. It may be incorrect or not specific enough.");

		else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     $("#directions").html("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.");
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     $("#directions").html("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.");
	     
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     $("#directions").html("The given key is either invalid or does not match the domain for which it was given.");

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     $("#directions").html("A directions request could not be successfully parsed.\n Error code: ");
	    
	   else $("#directions").html("An unknown error occurred.");
	   
	}

	function onGDirectionsLoad(){ 
      // Use this function to access information about the latest load()
      // results.

      // e.g.
      // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	}
