var map;
var gdir;
var geocoder = null;
var addressMarker;

function initialize() {
	if (GBrowserIsCompatible()) {      
		map = new GMap2(document.getElementById("map_canvas"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		gdir = new GDirections(map, document.getElementById("directions"));
		GEvent.addListener(gdir, "error", handleErrors);
		setDirections("Wilmington, NC");
	}
}

function setDirections(fromAddress) {
	gdir.load("from: " + fromAddress + " to: The Willows @34.23362535991965, -78.00071954727173");
}

function handleErrors(){
	if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
		alert("A directions request could not be successfully parsed.\nError code: " + gdir.getStatus().code);
	else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
		alert("A geocoding or directions request could not be successfully processed for unknown reasons.\n Error code: " + gdir.getStatus().code);
	else if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		alert("No location could be found for the specified address. This may be due to the address being relatively new.\n Error code: " + gdir.getStatus().code);
	else if (gdir.getStatus().code == G_GEO_UNAVAILABLE_ADDRESS)
		alert("The given address or the route for the given directions query cannot be returned due to legal reasons.\n Error code: " + gdir.getStatus().code);
	else if (gdir.getStatus().code == G_GEO_UNKNOWN_DIRECTIONS)
		alert("Directions could not be computed for the specified address. This is usually because no route is available, or we do not have data for that region.\n Error code: " + gdir.getStatus().code);
	else if (gdir.getStatus().code == G_GEO_TOO_MANY_QUERIES)
		alert("An unknown error occurred.  We are currently working on fixing the problem.");
	else alert("An unknown error occurred.");
}
