//GOOGLE MAPS

var gdir;
var geocoder = null;
var addressMarker;  
var map;
var localSearch = new GlocalSearch();


var icon = new GIcon();
icon.image = "http://www.toptoddler.co.uk/webapp/templates/images/google_pointer.png"; //set icon image
icon.shadow = "http://www.toptoddler.co.uk/webapp/templates/images/google_shade.png"; //set icon image shadow
icon.iconSize = new GSize(100, 91);
icon.shadowSize = new GSize(100, 91);
icon.iconAnchor = new GPoint(40, 60);


function initialize() {
      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map_canvas"));
		map.setCenter(new google.maps.LatLng(53.800499,-1.543837), 12);  //set loading location
        gdir = new GDirections(map, document.getElementById("directions")); 
		var marker = new GMarker(new GLatLng(53.800499,-1.543837),icon); //set icon location
		map.addOverlay(marker);
		//add controls
		var mapControl = new GMapTypeControl();
		map.addControl(mapControl);
		map.addControl(new GSmallMapControl());
	}
}
    
function usePointFromPostcode(postcode, callbackFunction) {
	
	localSearch.setSearchCompleteCallback(null, 
		function() {
			
			if (localSearch.results[0])
			{		
				var resultLat = localSearch.results[0].lat;
				var resultLng = localSearch.results[0].lng;
				var point = new GLatLng(resultLat,resultLng);
				callbackFunction(point);
			}else{
				alert("Postcode not found!");
			}
		});	
		
	localSearch.execute(postcode + ", UK");
}

function showPointLatLng(point) {
		//alert(" " + point.lat() + ", " + point.lng());
	gdir.load("from:  " + point.lat() + ", " + point.lng() +"  to: 53.800499,-1.543837" ); //set destination
}

