/**** 
 *
 * Contrôles possibles : 
 *
 * - GLargeMapControl()				=> Contrôles étendus avec glissière pour le zoom
 * - GSmallMapControl() 			=> Contrôles simplifié avec boutons + / - et les fleches
 * - GSmallZoomControl()			=> Contrôles simplifié avec boutons + / -
 * - GScaleControl()				=> Affichage de l'échelle
 * - GMapTypeControl()				=> Choix du type de carte (normale / sat. / hybride)
 * - GHierarchicalMapTypeControl()	=> Choix du type de carte avec des options avancées
 * - GOverviewMapControl()			=> Affiche la mini carte
 */

/**
 * Créé un marqueur standard
 *
 * @var GLatLng coordinates		Les coordonnées lat / lng du marqueur
 * @var string 	bubbleMessage	Le texte a afficher quand on clique sur le marqueur
 * @return GMarker
 **/
function createMarker ( coordinates, bubbleMessage ) {
	var marker = new GMarker ( coordinates, {draggable: false} );
	if ( bubbleMessage != undefined && bubbleMessage != "" ) {
		GEvent.addListener(marker,"click", function() {
			marker.openInfoWindowHtml(bubbleMessage);
		});
	}
	return marker;
}

/**
 * Créé un marqueur standard avec une couleur précise
 *
 * @var GLatLng coordinates		Les coordonnées lat / lng du marqueur
 * @var GLatLng color			La couleur du marqueur en hexa sans le # : ed1a22
 * @var string 	bubbleMessage	Le texte a afficher quand on clique sur le marqueur
 * @return GMarker
 **/
function createColoredMarker ( coordinates, color, bubbleMessage ) {
	var iconMarker	= MapIconMaker.createMarkerIcon({width: 36, height: 32, primaryColor: color});
	var marker 		= new GMarker ( coordinates, {draggable: false, icon: iconMarker} );
	if ( bubbleMessage != undefined && bubbleMessage != "" ) {
		GEvent.addListener(marker,"click", function() {
			marker.openInfoWindowHtml(bubbleMessage);
		});
	}
	return marker;
}

/**
 * Trouve les coordonnées Lat / Lng d'une adresse postale
 *
 * @var string address		L'adresse postale
 * @var function callback	La fonction a appeler une fois l'adresse trouvé. Un objet geoResponse lui sera transmit
 * @return void
 **/
function findCoordinatesFromAddress (address, callback) {
	if ( address != "" ) {
		geoCoder.getLocations(address, callback );
	}
}

/**
 * Ajouter une marqueur sur une carte
 *
 * @var objet reponseGeoCoder	La réponse du geocoder
 * @return void
 **/
function addMarkerFromGeoCoder( reponseGeoCoder ) {
	if ( !reponseGeoCoder || reponseGeoCoder.Status.code != 200 ) {
		$("infosAdresse").update("L'adresse saisie n'est pas connue");
	} else {
		var Position 			= reponseGeoCoder.Placemark[0];
		var Lat					= Position.Point.coordinates[1];
		var Lng					= Position.Point.coordinates[0];
		var markerCoordinates	= new GLatLng(Position.Point.coordinates[1], Position.Point.coordinates[0]);
		
		Map.addOverlay( createMarker ( markerCoordinates ) );
	}
}
