window.addEvent('domready', function() { 
	load();
});

var geocoder;
var map;
<?php
	$add = $ctx->here->address;
	$pos = $ctx->here->postcode;
	echo "var address='" . $add . ", " . $pos . "';";
?>
function load() {
  if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById("map"));
	geocoder = new GClientGeocoder();
	geocoder.getLocations(address, addToMap);
	map.addControl(new GSmallMapControl());
  }
}
function addToMap(response)
{
	if (!response || response.Status.code != 200) {
		 map.setCenter(new GLatLng(54.9, -3.427834), 5);
	}
	else{
		// Retrieve the object
		  place = response.Placemark[0];	
		  // Retrieve the latitude and longitude
		  point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);	
		  // Center the map on this point
		  map.setCenter(point, 13);	
		  // Create a marker
		  marker = new GMarker(point);	
		  // Add the marker to map
		  map.addOverlay(marker);	
		  // Add address information to marker
		  marker.openInfoWindowHtml('<b>${here/title_or_id}</b><br/>' + place.address);
	  }
}
