function initGMap(id){	
	var latlng = new google.maps.LatLng(47.040182,1.032715);
	var myOptions = {
		zoom: 5,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		navigationControl: true,
		scaleControl: true,
		mapTypeControl: true
	};
	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
	//--> Déclaration du géocoder
	var geocoder = new google.maps.Geocoder();
	var results;
	var status;	

	//--> Lecture du fichier XML pour récupération des adresses, de l'icône et du titre
	$.ajax({
		type: "GET",
		url: "http://www.echo-vert.fr/includes/contacts.xml",
		dataType: "xml",
		success: function(xml) {
			$(xml).find('marker').each(function(){
				var id = $(this).attr('id');
				var adresse = $(this).attr('adresse');
				var titre = 'Cliquez pour voir les coordonnées'; //$(this).attr('titre');
				var icone = $(this).attr('icone');
				var latitude  = $(this).attr('latitude');
				var longitude = $(this).attr('longitude');
					if (geocoder) {
						geocoder.geocode( { 'address': adresse}, function(results, status) {
						map.setZoom(5);
// 						alert(latitude);
						//geocoder.geocode({ 'address': adresse}, function(results, status) {
							//--> Définition de la position
							if ( latitude != '' && longitude != '' ) {
							  coordonneesGPS = new google.maps.LatLng(latitude, longitude);
// 							alert(coordonneesGPS);
							} else {
							  if ( isset(results[0]) ) {
								  coordonneesGPS = results[0].geometry.location;
								} else {
								  coordonneesGPS = new google.maps.LatLng('47.329783', '5.044241');
								}
							}
// 			                 alert(coordonneesGPS);
							
							var MarkerLatLng = coordonneesGPS;
							//var MarkerLatLng = results[0].geometry.location;
							//alert(MarkerLatLng);
// 							if (status == google.maps.GeocoderStatus.OK) {
								var myMarker = new google.maps.Marker({
									map: map,
									title: titre,
									position: MarkerLatLng,
									icon:icone
								});
								var str = $("#region-"+id).html();
								var myInfoWindow = new google.maps.InfoWindow({content:str});
								google.maps.event.addListener(myMarker, 'click', function() {
									myInfoWindow.open(map,myMarker);
								});
// 							} else {
// 								var erreur = '';
// 							}
						});
					}
			});
		}
	});
	
	ajusterFooter();
}

function closeMapInfoWindow(){
	for(var i=0;i<map.infoWindows.length;i++){
		map.infoWindows[i].close();
	}
}

//--> Affichage d'un point sur la carte en fonction d'un onClick par exemple
function zoomAddress(idDestination) {
	//--> Lecture du fichier XML pour récupération des adresses, de l'icône et du titre
	//--> Déclaration du géocoder
	var geocoder = new google.maps.Geocoder();
	var results;
	var status;
	
// 	var blocks=document.getElementsByTagName("div");
// 	for(var i=0;i<blocks.length;i++){
// 		if(blocks[i].name=="blockRegion"){
// 			blocks[i].style.display="none";
// 		}
// 	}
	for( x=0;x<1000;x++ ) {
		$("#region-"+x).slideUp('fast');
	}

	document.getElementById("region-"+idDestination).style.display="block";
	
	$.ajax({
		type: "GET",
		url: "http://www.echo-vert.fr/includes/contacts.xml",
		dataType: "xml",
		success: function(xml) {
			$(xml).find('marker').each(function(){
				var id = $(this).attr('id');
				var adresse = $(this).attr('adresse');
				var titre = 'Cliquez pour voir les coordonnées'; //$(this).attr('titre');
				var icone = $(this).attr('icone');
				var latitude  = $(this).attr('latitude');
				var longitude = $(this).attr('longitude');
				
				if (id == idDestination) {
					if (geocoder) {
						geocoder.geocode( { 'address': adresse}, function(results, status) {
							//--> Définition de la position
							//var MarkerLatLng = results[0].geometry.location;
							/*if (status == google.maps.GeocoderStatus.OK) {
								var myMarker = new google.maps.Marker({
									map: map,
									title: titre,
									position: MarkerLatLng,
									icon:icone
								});
								var str = $("#region-"+id).html();
								var myInfoWindow = new google.maps.InfoWindow({content:str});
								google.maps.event.addListener(myMarker, 'click', function() {
									myInfoWindow.open(map,myMarker);
								});
							} else {
								var erreur = '';
							}*/
							
							if ( latitude != '' && longitude != '' ) {
							  coordonneesGPS = new google.maps.LatLng(latitude, longitude);
// 							alert(coordonneesGPS);
							} else {
							  if ( isset(results[0]) ) {
								  coordonneesGPS = results[0].geometry.location;
								} else {
								  coordonneesGPS = new google.maps.LatLng('47.329783', '5.044241');
								}
							}
							
							var MarkerLatLng = coordonneesGPS;
							
							map.setCenter(MarkerLatLng);
							map.setZoom(16);
							//var MarkerLatLng = results[0].geometry.location;
							//alert(MarkerLatLng);
// 							if (status == google.maps.GeocoderStatus.OK) {
								var myMarker = new google.maps.Marker({
									map: map,
									title: titre,
									position: MarkerLatLng,
									icon:icone
								});
								var str = $("#region-"+id).html();
								var myInfoWindow = new google.maps.InfoWindow({content:str});
								google.maps.event.addListener(myMarker, 'click', function() {
									myInfoWindow.open(map,myMarker);
								});
						});
					}
				}
			});
		}
	});
} //--> End zoomAddress

//--> Ouvrir une fiche implantation
function openImplantation (idDestination) {
	$("#titre").slideUp('fast');
	$("#centre").slideUp('fast');
	$("#centreInfos").slideDown('fast');
	//$("#roadmapBlock").slideDown('fast');
	$("#centreInfosRetour").slideDown('fast');
	
	//--> Fermeture de tout ce qui traine
	for( x=0;x<1000;x++ ) {
		$("#ficheImp-"+x).slideUp('fast');
	}
	for( x=0;x<1000;x++ ) {
		$("#push-"+x).slideUp('fast');
	}
	
	//--> Lecture du fichier XML des implantations afin de récup adresse et titre
	$.ajax({
		type: "GET",
		url: "http://www.echo-vert.fr/includes/contacts.xml",
		dataType: "xml",
		success: function(xml) {
			$(xml).find('marker').each(function(){
				var id = $(this).attr('id');
				var adresse = $(this).attr('adresse');
				var titre = 'Cliquez pour voir les coordonnées'; //$(this).attr('titre');
				var icone = $(this).attr('icone');
				if (id == idDestination) {
					//--> Pour afficher proprement la destination
					$("#destination").html('<strong>'+titre+'</strong><br />'+adresse+'<input type="hidden" size="25" id="toAddress" name="to" value="'+adresse+'" />');
					
					//--> Ouverture de la fiche concernée
					$("#push-"+idDestination).slideDown('fast');
					$("#ficheImp-"+idDestination).slideDown('fast');
					
					//--> On centre la carte sur ce point
					zoomAddress(idDestination);
				}
			});
		}
	});
	return false;
} //--> End openImplantation

//--> Fermer une fiche implantation
function closeImplemantation () {
	$("#titre").slideDown('fast');
	$("#centre").slideDown('fast');
	$("#centreInfos").slideUp('fast');
	$("#centreInfosRetour").slideUp('fast');
	//$("#roadmapBlock").slideUp('fast');
	//$("#printRoadMap").slideUp('fast');
	
	for( x=0;x<1000;x++ ) {
		$("#ficheImp-"+x).slideUp('fast');
	}
	for( x=0;x<1000;x++ ) {
		$("#push-"+x).slideUp('fast');
	}
	//$("#roadmap").html('');
	//$("#roadmap").slideUp('fast');
	//$("#destination").html('<em>Sélectionnez une agence, merci.</em>');
	//--> Réinitialisation de la carte
	initGMap();
	return false;
} //End closeImplemantation

