/******************************************************************************************************************
**
**							FONCTIONS JAVASCRIPT POUR GOOGLE MAP SUR L ECRAN HOME VACANCES
**
*******************************************************************************************************************/




var GestionMapLocalisation = function()
{
	//================================
	// 		variables priv?es
	//================================
	var LatLonPoint = null;
	var FlagPictoTampon = null;
	
	
	//================================
	// 		m?thodes priv?es
	//================================
	var  createMarker = function (point,flagPicto) {
		 if(flagPicto!=1 && flagPicto){
		 	var img=dossierImages+"img/modules/cartographie/"+flagPicto;
		 }else{
		 	var img=dossierImages+"img/modules/cartographie/localisation.png"
		 }
		var marker = new GMarker(point, {icon: new GIcon(stdIconPoint, img)});		        
		return marker;
	};
	
	/**
	 * #1436#
	 * @author Yann Eugoné
	 * Fonction de callback utilisée par l'API google lorsque celle-ci a terminé la localisation d'une adresse
	 * @param json response     La reponse des serveurs google
	 * @return void
	 */
	var callBackGeolocalisationByAdress = function(response) {
		if (response && response.Status.code == 200) {
			place = response.Placemark[0];
			placePointOnMap(new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]));
		} else {
			placePointOnMap(LatLonPoint);
		}
	};
	
	var initMapLocalisation = function (flagPicto, sizePictoParam)
		{
			if (GBrowserIsCompatible()) {				    
			    //Initialisation de la carte
				if( (typeof(sizeOfDiv) != "undefined") && sizeOfDiv)
					mapLoc = new GMap2(document.getElementById("mapLocalisation"),{ size: new GSize(400,400)});
				else
					mapLoc = new GMap2(document.getElementById("mapLocalisation"));
				
				// #1436#
				FlagPictoTampon = flagPicto;
				LatLonPoint = new GLatLng(latCentre, longCentre);
				
				if( (typeof(ville) != "undefined") && (typeof(cp) != "undefined") && (typeof(adresse) != "undefined") ) {
					var geocoder = new GClientGeocoder(); 
					geocoder.getLocations(adresse + ',' + cp + ',' + ville, callBackGeolocalisationByAdress);
				} else {
					placePointOnMap(LatLonPoint);
				}
				// FIN - #1436#
			}// if GBrowserIsCompatible		
			else{
				document.getElementById("message").innerHTML = "Votre navigateur n'est pas compatible avec Google Maps !";			
			} 
		
		};
	/**
	 * #1436#
	 * @author Yann Eugoné
	 * Place un point sur la carte google et centre sur celui-ci
	 * @param GLatLng paramPoint     Le point à placer sur la carte
	 * @return void
	 */
	var placePointOnMap = function(paramPoint){
		if( (typeof(zoom) != "undefined") && zoom)
			mapLoc.setCenter(paramPoint, zoom);
		else
			mapLoc.setCenter(paramPoint,13);
		
		//Ajout des controles
		mapLoc.addControl(new GSmallMapControl());
		mapLoc.addControl(new GMapTypeControl());
		
		stdIconPoint = new GIcon();
		
	   // alert(sizePictoParam);
		if( (typeof(sizePictoParam) == "undefined") || !sizePictoParam){
			stdIconPoint.iconSize = new GSize(27,19);
		}
		else{
			size = sizePictoParam.split('|');
			stdIconPoint.iconSize = new GSize(size[0], size[1]);
		}
		stdIconPoint.iconAnchor = new GPoint(14,9);
		
		//Ajout du point sur la carte    
		if(FlagPictoTampon || (paramPoint.lat() && paramPoint.lng())){
			var marker = createMarker(paramPoint,FlagPictoTampon);
			mapLoc.addOverlay(marker);
		}
		else{}
	};
	return {
		//================================
		// 		variables publiques
		//================================
		
		//================================
		// 		m?thodes publiques
		//================================
		init: function (flagPicto,sizePicto)
			{
				initMapLocalisation(flagPicto,sizePicto);
			} // init
	}; // public	
}();		

function onLoad(flagPicto,sizePicto)
{
	GestionMapLocalisation.init(flagPicto,sizePicto);
}

