
	
	// Filename: directions_script.js
	// Purpose:  Provides the Google Map functions
	
	// This file is based on the Google Maps API which is Copyright (c) Google.
	
	// Author: Andrew Hennessy
	// Copyright (c) Andrew Hennessy 2007. 
	// All rights reserved.
	
	// Date: 25th Oct 2007

	// Create a directions object and register a map and DIV to hold the 
    // resulting computed directions

    var gmap;
    var directionsPanel;
    var gdir;
	
	function initialise() 
	{
	  gmap = new GMap2(document.getElementById("MapAndPanelMap"));
	  directionsPanel = document.getElementById("MapAndPanelPanel");
	  gdir = new GDirections(gmap, directionsPanel);
	  GEvent.addListener(gdir, "error", handleErrors);
      displayDirections("Davey Street, Hobart, TAS");
    }
	
	function displayDirections(addressfrom)
	{
		//gdir.load(addressfrom + " to " + HLAT + ", " + HLONG);
		gdir.load(addressfrom + " to Bruny Island Ferry Terminal @-43.127347, 147.256937");
	}
	
	function handleErrors()
	{
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("The directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. This means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("The directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("An unknown error occurred.");
	   
	}