var mapLat = '';
var mapLong = '';
var icon = '';
function updateMapCenter(lat, lng, zoom) {
	if (lat) mapLat = lat;
	if (lng) mapLong = lng;

	var latLng = new GLatLng(mapLat, mapLong);
	map.setCenter(latLng);
	if (zoom) map.setZoom(zoom);
}

function centerMapOnPostcode(postcode) {
	var geocoder = new GlocalSearch();

	geocoder.setSearchCompleteCallback(null, function() {
		if (geocoder.results[0]) {
			var resultLat = geocoder.results[0].lat;
			var resultLng = geocoder.results[0].lng;
			updateMapCenter(resultLat, resultLng);
			map.setZoom(11);
			addMarker(resultLat, resultLng);
		}
	});

	geocoder.execute(postcode + ", UK");
}

function addMarker(lat, lng) {
	var latLng = new GLatLng(lat, lng);

	icon.image = "http://www.google.com/mapfiles/marker.png";
	icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	icon.iconSize = new GSize(20, 34);
	icon.shadowSize = new GSize(37, 34);
	icon.iconAnchor = new GPoint(10, 34);
	marker = new GMarker(latLng, icon);
	map.clearOverlays();
	map.addOverlay(marker);

}

