	var map = null;		// instance de la map
	var geocoder = null;	// geocoder, recherche
	var div_map = "";	// nom du div pour la map
	var div_street = "";	// nom du div pour la div du street
	var tab_points = new Array(); // tableau des infos points
	var markers = new Array();	// tableau des marqueurs
	var moi = null;
	var option_itineraire = false;
	var gdir;	// direction
	var myPano;	//street view
	
	
	function initialize() {
		if (GBrowserIsCompatible()) {
			map = new GMap2(document.getElementById(div_map));
			geocoder = new GClientGeocoder();
			map.setUIToDefault();
			map.disableScrollWheelZoom();
			
			charger_liste_point();
			
			if(option_itineraire){
				gdir = new GDirections(map, document.getElementById("itineraire_"+div_map));
				GEvent.addListener(gdir, "load", onGDirectionsLoad);
				GEvent.addListener(gdir, "error", handleErrors);
			}
		}
    }
	
	
	function initialize_street(lat, long) {
		var lieu = new GLatLng(lat,long);
		panoramaOptions = { latlng:lieu };
		myPano = new GStreetviewPanorama(document.getElementById(div_street), panoramaOptions);
		
		GEvent.addListener(myPano, "error", handleNoFlash);
		GEvent.addListener(myPano, "yawchanged", handleOkFlash);
	}
	
	function handleOkFlash(location){
		var bloc_360 = document.getElementById(div_street).parentNode.previousSibling;
		bloc_360.style.display = 'block';
	}
	
	function handleNoFlash(errorCode) {
		if(errorCode==600){
			var bloc_360 = document.getElementById(div_street).parentNode.parentNode.parentNode;
			if(bloc_360.className=='bloc') bloc_360.style.display = 'none';
		}
		return;
	}
	
	/*
	function handleViewInit(location) {
		alert("OK");
		return;
	}
	*/
	
	function charger_liste_point(){
		// géo position du client si dispo
		if(option_itineraire && google.loader.ClientLocation.latitude && google.loader.ClientLocation.longitude){
			var _pobj_temp = new Object();
			_pobj_temp.mode = 'geo';
			_pobj_temp.long = google.loader.ClientLocation.longitude;
			_pobj_temp.lat = google.loader.ClientLocation.latitude;
			_pobj_temp.txt_html = "";
			_pobj_temp.type = 'moi';
			_pobj_temp.active_drag = 1;
			
			moi = _pobj_temp;
			tab_points.push(moi);
		}
		
		// affichage des points
		map.clearOverlays();
		
		//map.setCenter(new GLatLng(43.0705451, 5.7902359), 13);
		if(tab_points.length==0) map.setCenter(new GLatLng(43.0705451, 5.7902359), 13);
		else{ 
			jQuery.each(tab_points, function() {
				showLocationByLongLat(this.lat, this.long, this.type);
			});
		}
	}
	
	function listener_points_ok(){
		if(markers.length==tab_points.length){
			// centrage de la carte
			var bounds = new GLatLngBounds();
			for(i in markers) {
				var marker = markers[i];
				var im = marker.getLatLng();
				eval("bounds.extend(new GLatLng"+im+")");
			}
			map.setCenter(bounds.getCenter(), (map.getBoundsZoomLevel(bounds)-1));
		}
	}
	
	function showLocationByLongLat(lat, long, type) {
		var point = new GLatLng(lat, long);
		
		// Create our "tiny" marker icon
		var ico_lieu = new GIcon(G_DEFAULT_ICON);
		ico_lieu.image = "/_design/img/gmap/gmap_"+type+".png";
		ico_lieu.shadow = "/_design/img/gmap/gmap_"+type+"_ombre.png";
		ico_lieu.iconSize = new GSize(20, 34/*20*/);
		ico_lieu.shadowSize = new GSize(37, 34);
		//ico_lieu.iconAnchor = new GPoint(6, 20);
		//ico_lieu.infoWindowAnchor = new GPoint(5, 1);

		var marker = new GMarker(point, {draggable: true, icon: ico_lieu});
		marker.disableDragging();
		markers.push(marker);
		
		
		map.addOverlay(marker);
		var pos = (markers.length-1);
		
		if(type=='moi'){
			if(tab_points[pos].active_drag){
				marker.enableDragging();
				GEvent.addListener(marker, 'dragend', function() {	var new_coord = marker.getLatLng();
																	moi.lat = new_coord.lat();
																	moi.long = new_coord.lng();
																});
			}
		}
		else{
			if(tab_points[pos].active_drag){
				marker.enableDragging();
				GEvent.addListener(marker, 'dragstart', function() { marker.closeInfoWindow() });
				GEvent.addListener(marker, 'dragend', function() { var new_coord = marker.getLatLng(); 
																   //alert("lat:"+new_coord.lat()+" - lng:"+new_coord.lng());
																 });
			}
			
			//GEvent.addListener(marker, 'mouseover', function() { marker.openInfoWindowHtml(tab_points[pos].txt_html); });
			
			marker.openInfoWindowHtml(tab_points[pos].txt_html);
			if(tab_points[pos].txt_html){
				GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(tab_points[pos].txt_html);});
				//document.location.href = tab_points[pos].url;
			}
		}
		
		
		listener_points_ok();
	}
	
	function setDirections(locale) {
		var dest = markers[0].getLatLng();
		var tab_points_dir = new Array(moi.lat+","+moi.long, dest.lat()+","+dest.lng());
		
		map.clearOverlays();
		gdir.clear();
		gdir.loadFromWaypoints(tab_points_dir, { "locale": locale });
    }
	
	function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	   else alert("An unknown error occurred.");
	}

	function onGDirectionsLoad(){ 
      // Use this function to access information about the latest load() results.
	}