var map;
var gDir;

function mapLoad() {
	if (GBrowserIsCompatible()) {
	    map = new GMap2(document.getElementById("gMap_directions"));
	    
	    gDir = new GDirections(map, document.getElementById("gDirections"));
	    GEvent.addListener(gDir, "load", onGDirectionsLoad);
	    GEvent.addListener(gDir, "error", handleErrors);

		map.addControl(new GScaleControl());

		map.addMapType(G_PHYSICAL_MAP); // Add terrain map type
	    map.setMapType(G_NORMAL_MAP);
		
		var mapControl = new GHierarchicalMapTypeControl();
		mapControl.clearRelationships();
		mapControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Labels", false);
		map.addControl(mapControl); // Add control after you've specified the relationships

		map.enableScrollWheelZoom();
		map.setCenter(new GLatLng(52.5, -0.75), 7);

		// Removing unwanted Google parts
		//var gDiv = document.getElementById("gMap_directions");
		//gDiv.childNodes[1].style.display = 'none'; // Hide Google logo
		//gDiv.childNodes[2].style.display = 'none'; // Hide Terms of Use text
		//gDiv.childNodes[4].style.left = '8px'; // Move map scale further left
	}
}

function setDirections() {
    var gFromAddress = document.getElementById("gFromAddress");
    var gToAddress = document.getElementById("gToAddress");

    if (gFromAddress.value != "" && gToAddress.value != "") {
        gDir.load("from: " + gFromAddress.value + ",uk to: " + gToAddress.value, { "locale": "en" });
    }
}

function handleErrors() {
    alert("Sorry there was an error with your request.")
}

function onGDirectionsLoad() {
    // Directions returned
}

