var map = null;

function load() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		if (coord_yn != 0 ) {
        	map.setCenter(new GLatLng(coord_1, coord_2), zoom);
        	renderMap();
		}
		else {
			// Create new geocoding object
      		geocoder = new GClientGeocoder();
      		// Retrieve location information, pass it to addToMap()
      		geocoder.getLocations(address, addToMap);
		}
	}
}

function renderMap() {
	map.addControl(new GLargeMapControl());
  	map.addControl(new GScaleControl());
  	if(mapType == 1)
  		map.setMapType(G_NORMAL_MAP);
  	else if(mapType == 2)
  		map.setMapType(G_HYBRID_MAP);
  	else
  		map.setMapType(G_SATELLITE_MAP);
  
  	var point = new GLatLng(coord_1,coord_2);
  	var marker = createMarker(point)
  	map.addOverlay(marker);
}

// This function adds the point to the map

function addToMap(response)
{
	// Retrieve the object
  	place = response.Placemark[0];
  	// Retrieve the latitude and longitude
  	coord_1 = place.Point.coordinates[1];
  	coord_2 = place.Point.coordinates[0];
  	// Center the map on this point
  	map.setCenter(new GLatLng(coord_1,coord_2), zoom );
  	renderMap();
}
	
function createMarker(point) {
	var marker = new GMarker(point);
//    GEvent.addListener(marker, "click", function() {
    	//marker.openInfoWindowHtml(address);
    //});
    return marker;
}


