var gdir;
var geocoder = null;
var addressMarker;  
var map;
var localSearch = new GlocalSearch();

var icon = new GIcon();
icon.image = "http://dev.cleverclover.com/stg-amenities/webapp/templates/images/map-marker.png"; //set icon image
icon.shadow = "http://dev.cleverclover.com/stg-amenities/webapp/templates/images/map-marker-shadow.png"; //set icon image shadow
icon.iconSize = new GSize(153, 83);
icon.shadowSize = new GSize(153, 83);
icon.iconAnchor = new GPoint(40, 60);


function initialize() {
      if (GBrowserIsCompatible()) {  
        map = new GMap2(document.getElementById("map_canvas"));
		map.setCenter(new google.maps.LatLng(53.650132,-1.526585), 13);  //set loading location
        gdir = new GDirections(map, document.getElementById("directions")); 
        
		var marker = new GMarker(new GLatLng(53.649293,-1.525791),icon); 
		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.649293,-1.525791" ); //set destiination
}


