//google.load("maps", "2.x",{"other_params":"sensor=true"}); // ralenti GMAP
google.load("maps", "2.x");

var map;
var geocoder;

function initialize() {
	
	map = new google.maps.Map2(document.getElementById("map_canvas"));
	//map.setCenter(new google.maps.LatLng(48.211862,-3.4552), 8); // = "BZH focused"
	map.setUIToDefault();	
	geocoder = new GClientGeocoder();
	
}

// 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) {
	map.clearOverlays();
	if (!response || response.Status.code != 200) {
		var adresse = $('#adresseComplete').text();
		//alert("Désolé, l'adresse " + adresse + " n'a pas pu être géolocalisée par GoogleMap");
	} 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 + '<br>' + '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
		marker.openInfoWindowHtml(place.address);
	}
}

// findLocation(address) is used to enter the sample addresses into the form.
// ex : onclick="findLocation('1 Telegraph Hill Blvd, San Francisco, CA, USA');return false;"
function findLocation(address) {	
	geocoder.getLocations(address, addAddressToMap);
}
