	var map;
    var geocoder;
	var zoominterval = null;
	var _mapLoaded = false;
	
    function loadMap() {
      if (!defaultX) {
		defaultX = -41.47566020027821;
	  }
	  if (!defaultY) {
		defaultY = 173.5400390625;
	  }
	  if (!defaultZoom) {
		defaultZoom = 5;
	  }
	  map = new GMap2(document.getElementById("map_canvas"));
      map.setCenter(new GLatLng(defaultX, defaultY), defaultZoom);
	  map.addControl(new GSmallMapControl());
      geocoder = new GClientGeocoder();
	  _mapLoaded = true;
    }
	
    function zoomTheMap() {
        // stop zoom action & abort map requests, if map is not visible
        if ( !$( map.getContainer() ).is(':visible') || map.getZoom() >= 13 ) {
            clearTimeout(zoominterval);
            return;
        }
        
        map.setZoom(map.getZoom()+2);
        zoominterval = setTimeout("zoomTheMap()", 2000);
    }
    
    function addAddressToMap(response) {
      map.clearOverlays();
      if (!response || response.Status.code != 200) {
        alert("Sorry, we were unable to geocode that address");
		clearTimeout(zoominterval);
		map.setZoom(defaultZoom);
      } else {
        
		place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
		marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml(place.address.replace(',', ',<br>') + '<br>' +
          '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
		map.setCenter(point);
		
		zoominterval = setTimeout("zoomTheMap()", 2000);
      }
    }
    function findLocation(address) {
      //if (!_mapLoaded)
	  loadMap();
	  map.setZoom(defaultZoom);
	  geocoder.getLocations(address, addAddressToMap);
    }
