	var map = null;
    var geocoder = null;

    function initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));        
        map.setUIToDefault();
        geocoder = new GClientGeocoder();
      }
    }

    function showProvinceMap() {
		if (GBrowserIsCompatible()) {
			map = new GMap2(document.getElementById("map_canvas"));      			
		    map.setCenter(new GLatLng(40.4166909, -3.7003454), 5);        
		    map.setMapType(G_PHYSICAL_MAP);		    
		}
    }
    
    function addProvinceOverlay(province, message, link, lat, lon ) {
      var point = new GLatLng( lat, lon );
 	  var newIcon = getIcon(province);	  
  	  var marker = new GMarker( point, { icon: newIcon } );
	  marker.value = province;
	  GEvent.addListener(marker, "click", function() {
		  var newIcon = getIcon(province);
		  var myHtml = "<b>" + province + "</b><br/><br/><a href='" + link +"'>See dive centers in " + province + "</a>";
		  map.openInfoWindowHtml(point, myHtml);
	  });
	  map.addOverlay( marker );
	  return;
    }
    
    /**
     * @see http://gmaps-utility-library.googlecode.com/svn/trunk/mapiconmaker/1.1/examples/markericonoptions-wizard.html
     */
    function getIcon(province) {
    	var iconOptions = {};
    	iconOptions.width = 70;
    	iconOptions.height = 12;
    	iconOptions.primaryColor = "#007395";
    	iconOptions.label = province;
    	iconOptions.labelSize = 8;
    	iconOptions.labelColor = "#ffffff";
    	iconOptions.shape = "roundrect";

    	var icon = MapIconMaker.createFlatIcon(iconOptions);
    	return icon;
    }
    
    function createMarker(point, number) {
    	  var marker = new GMarker(point);
    	  var message = ["This","is","the","secret","message"];
    	  marker.value = number;
    	  GEvent.addListener(marker, "click", function() {
    	    var myHtml = "<b>#" + number + "</b><br/>" + message[number -1];
    	    map.openInfoWindowHtml(point, myHtml);
    	  });
    	  return marker;

    	}
    
    
    function showAddress(address) {
      if(address == '') {
    	  $('#map_canvas').hide();
    	  return;
      }
    	initialize();
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              //marker.openInfoWindowHtml(address);
            }
          }
        );
      }
    }
     
    $(window).load( function() { 
    	//initialize();
    	//showAddress( $('#map-address').val()  );    	
    }); 
    
