/**
 * Access the Google geocoder directly
 * e.g: http://maps.google.com/maps/geo?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA&output=xml&key=abcdefg
 */

var map;
var geocoder;

function load(location) {
   var address = location;
   map = new GMap2(document.getElementById("map"));
   geocoder = new GClientGeocoder();
   if (location) {
       geocoder.getLocations(address, addAddressToMap);
   }
   else {
       map.setCenter(new GLatLng(-25.274398,133.775136, 31.261265,59.765625),4);
   }
}

// addAddressToMap() is called when the geocoder returns an
// answer.  It adds a marker to the map with an open info window
// showing the nicely formatted version of the address and the country code.
function addAddressToMap(response) {
   // Create our "tiny" marker icon
   var icon = new GIcon();

   map.clearOverlays();
   if (!response || response.Status.code != 200) {
      alert("Sorry, we were unable to geocode that address");
   } else {

      // Zooming & panning features
      map.addControl(new GLargeMapControl());
      // Adds the small navigation map in the bottom right corner
      map.addControl(new GOverviewMapControl());

      place = response.Placemark[0];
      point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
      map.setCenter(new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]),12);

      icon.image = "http://www.aussietraders.com.au/maps_icon.png";
      icon.iconSize = new GSize(22, 30);
      icon.iconAnchor = new GPoint(6, 20);
      icon.infoWindowAnchor = new GPoint(5, 1);
      marker = new GMarker(point,icon);
      map.addOverlay(marker);
      marker.openInfoWindowHtml(place.address);
   }
}
var i=0;
function loadMap(iframe, location) {
	if (!i++) {
		iframe.src=location;
	}
}