function load(v) {		
	if (GBrowserIsCompatible()) {
	
		var map = new GMap2(document.getElementById("map")); //initialisation de la map
		
		var cssBackground = {
			'background-image' : 'url(img/loader.gif)',
			'background-repeat' : 'no-repeat',
			'background-position' : 'center center'
		}
		$("#map").css(cssBackground); // ajout d'une image de loading sur le fond de la carte pendant son chargement initial
		
		map.addControl(new GSmallZoomControl(), new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(10, 50))); //positionnement outils de controle format petit (zoom + / -)  en bas à gauche 		
		map.setMapType(G_PHYSICAL_MAP); // choix du type de carte 
		map.suppressCopyright = true; // suppression du copyright (fonctionne pas vraiment)
		option_info = { noCloseOnClick:true, buttons:{close:{show:4}} }; //initialisation des options des bulles d'infos (1 : pas de fermeture de la bulle quand clic sur la carte, 2 : pas la croix pour fermer la bulle)
		marker = 0;	// initialisation du marker
		IconSmos = new GIcon(G_DEFAULT_ICON); // initialisation d'un nouveau marker
		IconSmos.image = "img/smosvision_marqueur.png"; // choix d'une image pour le nouveau marker
		IconSmos.shadow = ""; // pas d'image d'ombre pour le nouveau marker
		IconSmos.iconSize = new GSize(21, 34); // taille du nouveau marker
		IconSmos.iconAnchor = new GPoint(10, 34); // ancre de pointage du nouveau marker
		IconSmos.infoWindowAnchor = new GPoint(10, 1); // ancre de pointage de la cible de l'info bulle
		markerOptions = { icon:IconSmos, draggable: false }; // définition des options du marker (1 : image perso, 2 : marker non déplaçable)
		nb = 20; // nombre de smos récupéré par appel au webservice
		page = 0; // initialisation de la page pour les requêtes webservices
		
		if((v == 'tec') || (v == 'trains') || (v == 'etranger') || (v == 'lieux_publics')){
			var recherche = v;
			pays = "";
		}else if(v == 'province' || v == 'paris' || v == 'monde'){
			var recherche = v;
			pays = "";
		}else{
			if(v == '' || v == undefined || v == null) v = "province";
			pays = v;
			var recherche = v;
		}		
		
/* 		if((v == 'tec') || (v == 'trains') || (v == 'etranger') || (v == 'lieux_publics')){
			var recherche = 'type='+v;
			pays = "";
		}else if(v == 'province' || v == 'paris' || v == 'monde'){
			var recherche = 'zone='+v;
			pays = "";
		}else{
			if(v == '' || v == undefined || v == null) v = "province";
			pays = v;
			var recherche = 'zone='+v;
		}	 */		
		var suivant = 0; // compteur d'appel des webservices
		update_flux(map,pays,recherche,nb,page,suivant); // appel de la fonction de récupération des smos
	
	}
}

function update_flux(map,pays,recherche,nb,page,suivant){	
	$.getJSON("scripts/reqSmos.php?recherche="+recherche+"&nb="+nb+"&page="+page ,
		function(data){		
			if(suivant == 0) var tempo = 0;				 	
			else var tempo = 10000;
			nb = nb - 1;
			
			$.each(data, function(i,item){
				var numero = i;
                var avatarUser;

//if(numero == '1'){

                $.get("scripts/avatarSmos.php?idSmos="+item.idSmos, function(avatar){
                    if(avatar == 0 || avatar == '0' ){
                       style_txt = "float:left;";
                       avatarUser = "";
                    }else{
                        avatarUser = '<img src="'+avatar+'" />';
                        style_txt = "float:left; width:200px; margin-left:10px; min-height:100px;";
                    }
                


                    if(item.sexeSmos == "F") var sexSmos = "<span style=\"color:#993399;\">une femme</span>";
                    else var sexSmos = "<span style=\"color:#993399;\">un homme</span>";

                    if(item.ageDebutSmos == 0) var ageDebSmos = "18";
                    else var ageDebSmos = item.ageDebutSmos;

                    if(item.ageFinSmos == 0) var ageFSmos = "100";
                    else var ageFSmos = item.ageFinSmos;

                    if(item.commune != null){
						var contenuCommune = " à "+item.commune; 
					}else{
						var contenuCommune = "";
					}	
                    var contenuCodePostal = "";
                    var contenuDepartement = "";					
                    /* if(item.codePostal != null) var contenuCodePostal = " ("+item.codePostal+")"; else var contenuCodePostal = "";
						if(item.departement != null) var contenuDepartement = " "+item.departement; else var contenuDepartement = ""; */
						
                    if(item.typeLpSmos != null && item.typeLpSmos != 'autre' && item.type2LpSmos != null && item.type3LpSmos != null) var contenuOu = item.typeLpSmos+", "+item.type2LpSmos+", "+item.type3LpSmos;
                    else if(item.typeLpSmos != null && item.typeLpSmos != 'autre' && item.type2LpSmos != null) var contenuOu = item.typeLpSmos+", "+item.type2LpSmos;
                    else if(item.typeLpSmos != null && item.typeLpSmos != 'autre' && item.type3LpSmos != null) var contenuOu = item.typeLpSmos+", "+item.type3LpSmos;
                    else if(item.typeLpSmos != null && item.typeLpSmos != 'autre') var contenuOu = item.typeLpSmos;
					else if(item.typeLpSmos == 'autre' && item.type2LpSmos != null && item.type3LpSmos != null) var contenuOu = item.type2LpSmos+", "+item.type3LpSmos;
					else if(item.typeLpSmos == 'autre' && item.type2LpSmos != null) var contenuOu = item.type2LpSmos;
                    else var contenuOu = "";					

/*                     if(item.typeLpSmos != null && item.typeLpSmos != 'autre' && item.type2LpSmos != null && item.type3LpSmos != null) var contenuOu = item.typeLpSmos+", "+item.type2LpSmos+", "+item.type3LpSmos;
                    else if(item.typeLpSmos != null && item.typeLpSmos != 'autre' && item.type2LpSmos != null) var contenuOu = item.typeLpSmos+", "+item.type2LpSmos;
                    else if(item.typeLpSmos != null && item.typeLpSmos != 'autre' && item.type3LpSmos != null) var contenuOu = item.typeLpSmos+", "+item.type3LpSmos;
                    else if(item.typeLpSmos != null && item.typeLpSmos != 'autre') var contenuOu = item.typeLpSmos;
                    else var contenuOu = ""; */

					if(recherche == 'etranger'){
						if(item.villePaysEtrangerSmos != null) var villePaysEtrangerSmos = ' à '+item.villePaysEtrangerSmos;
						else var villePaysEtrangerSmos = '';
						var contenuEtranger = item.paysEtrangerSmos+villePaysEtrangerSmos;
					}else{
						var contenuEtranger = '';
					}
					
					
					
					
					if(item.typeLieuSmos == 'trains'){
						if(item.nomLigne != 'TGV' && item.nomLigne != 'iDTGV' && item.nomLigne != 'Eurostar' && item.nomLigne != 'Thalys' && item.nomLigne != 'Lyria' && item.nomLigne != 'Artesia' && item.nomLigne != 'Elipsos' && item.nomLigne != 'Corail TEOZ'){
							var contenuTrain = 'TER, ligne '+item.nomLigne+', '+item.station1+' >> '+item.station2;
						}else{
							var contenuTrain = 'Dans un '+item.nomLigne+', '+item.station1+' >> '+item.station2;
						}
					}else{
						var contenuTrain = '';
					}
					
					
					
					if(item.typeLieuSmos == 'tec'){
						if(item.station1 == item.station2){
							var contenuTec = item.typeLigne+', '+item.nomVille+' : ligne '+item.nomLigne+' ('+item.station1+')';
						}else{
							var contenuTec = item.typeLigne+', '+item.nomVille+' : ligne '+item.nomLigne+' ('+item.station1+' - '+item.station2+')';
						}
					}else{
						var contenuTec = '';
					}					
					
					
					
					
					
                    if(contenuOu == '' && (contenuCommune != '' || contenuCodePostal != '' || contenuDepartement != '')){
						var contenuComplet = contenuTec+contenuTrain+contenuEtranger+contenuCommune+contenuCodePostal+contenuDepartement;
					}else{
						var contenuComplet = contenuTec+contenuTrain+contenuEtranger+contenuOu+contenuCommune+contenuCodePostal+contenuDepartement;
					}
					
					var codeSmos = item.codeSmos;

					//onclick=\"visuSmos('"+item.idSmos+"');\"
                    var contenuSmos = "<div class=\"text_info_bulle\">"                                    
                                    + "<div style=\"color:#999966; font-weight:bold; float:left; clear:both; width:300px; margin-bottom:10px; \">"+contenuComplet+"</div>"
                                    + "<div style=\"float:left;\">"+avatarUser+"</div>"
                                    + "<div style=\""+style_txt+"\"><span class=\"gras\">Tu es "+sexSmos+", entre "+ageDebSmos+" et "+ageFSmos+" ans.<br /><br />"
                                    + coupe_texte(item.detailSmos, 150)+"</span></div>"
                                    + "<div class=\"texteSmos\" style=\"width:300px;\">"+coupe_texte(item.texteSmos, 150)+"</div><br /><br />"
                                    + "<div style=\"clear:both; float:right; margin-top:10px;\"><a href=\"http://www.dilelui.com/smos.php?cd="+codeSmos+"\" target=\"_blank\" style=\"color:#993399; font-weight:bold; font-size:14px;\">VOIR LE SmOS</a></div>";
									+ "<div style=\"clear:both; float:left; width:1px; height:1px; \"> </div></div>";

									
/*                     var contenuSmos = "<div class=\"text_info_bulle\">"                                    
                                    + "<div style=\"color:#999966; font-weight:bold; float:left; clear:both; width:300px; margin-bottom:10px; \">"+contenuComplet+"</div>"
                                    + "<div style=\"float:left;\">"+avatarUser+"</div>"
                                    + "<div style=\""+style_txt+"\"><span class=\"gras\">Tu es "+sexSmos+", entre "+ageDebSmos+" et "+ageFSmos+" ans.<br /><br />"
                                    + coupe_texte(item.detailSmos, 150)+"</span></div>"
                                    + "<div class=\"texteSmos\" style=\"width:300px;\">"+coupe_texte(item.texteSmos, 150)+"</div><br /><br />"
                                    + "<div style=\"clear:both; float:right; margin-top:10px;\">";
									+ "<a href=\"http://www.dilelui.com/smos.php?cd="+codeSmos+"\" target=\"_blank\" style=\"color:#993399; font-weight:bold; font-size:14px;\">VOIR LE SmOS</a></div></div>";
									+ "<div style=\"clear:both; float:left; width:1px; height:1px; \"> </div> "; */

                    if(item.typeLieuSmos == 'lieux_publics'){
                        setTimeout(function() {carteSmos_gps(map, item.latSmos, item.lngSmos, contenuSmos, pays, numero, recherche, nb, page);}, tempo);
                    }else if(item.typeLieuSmos == 'tec'){
                        if(item.nomVille != null){
                            presence = item.nomVille.indexOf('Paris', 0);
                            if(presence != -1) var location = item.station1+", Paris";
                            else var location = item.station1+", "+item.nomVille;
                        }else{
                            var location = item.station1+", Paris";
                        }
                        setTimeout(function() {carteSmos_geocode(map, location, contenuSmos, numero, recherche, nb, page);}, tempo);
                    }else if(item.typeLieuSmos == 'trains'){
                        presence = item.station1.indexOf('TGV', 0);
                        if(presence != -1) var location = item.station1.substr(0, presence)+", FRANCE";
                        else var location = item.station1+", FRANCE";
                        setTimeout(function() {carteSmos_geocode(map, location, contenuSmos, numero, recherche, nb, page);}, tempo);
                    }else if(item.typeLieuSmos == 'etranger'){
                        if((item.paysEtrangerSmos != undefined) && (item.villePaysEtrangerSmos != undefined)){
                            var location = item.villePaysEtrangerSmos+", "+item.paysEtrangerSmos;
                            setTimeout(function() {carteSmos_geocode(map, location, contenuSmos, numero, recherche, nb, page);}, tempo);
                        }else if(item.paysEtrangerSmos != undefined){
                            var location = item.paysEtrangerSmos;
                            setTimeout(function() {carteSmos_geocode(map, location, contenuSmos, numero, recherche, nb, page);}, tempo);
                        }else if(item.villePaysEtrangerSmos != undefined){
                            var location = item.villePaysEtrangerSmos;
                            setTimeout(function() {carteSmos_geocode(map, location, contenuSmos, numero, recherche, nb, page);}, tempo);
                        }
                    }
                    tempo = tempo + 10000;


                 });
//}

			});
		}
	); 	
}

//si pas de coordonnées GPS
function carteSmos_geocode(map, location, contenuSmos, numero, recherche, nb, page){	
	$.post("scripts/reqFlux.php", { location:location }, function(data) {	
		var vecteur = data.split('|||');
		var coord = vecteur[0];
		var test_location = vecteur[1];

		if(test_location == 1){		
			var coordonne = coord.split('&&');
			var g_lat = coordonne[0];
			var g_lng = coordonne[1];
			carteSmos_gps(map, g_lat, g_lng, contenuSmos, location, numero, recherche, nb, page);
		}else{	
			var geocoder = new GClientGeocoder();
			geocoder.getLatLng(
				location,
				function(point) {					
					if(point != null){	
					
						var g_lat = point.y;
						var g_lng = point.x;

						$.post("scripts/ajoutVille.php", { ville:location, lat:g_lat, lng:g_lng });
						var point = new GLatLng(g_lat, g_lng);	
						
						if(recherche == 'tec') zoom = 13;
						else if(recherche == 'etranger') zoom = 4;
						else if(recherche == 'paris') zoom = 12;
						else zoom = 7;		
	
						if(marker) map.panTo(point, zoom);			
						else map.setCenter(point, zoom);
						
						if(marker) marker.hide();
						marker = new GMarker(point, markerOptions);
						map.addOverlay(marker);	
						marker.openInfoWindowHtml(contenuSmos, option_info);								
						GEvent.addListener(marker,"click", function() {
							marker.openInfoWindowHtml(contenuSmos, option_info);
						}); 	
					}						
				}							
			);
		}	
	});		
	if(numero == nb){
		page++;
		nb++;
		suivant = 1;
		update_flux(map,pays,recherche,nb, page, suivant);
	}			
}

//si coordonnées GPS
function carteSmos_gps(map, lat_smos, lng_smos, contenuSmos, pays, numero, recherche, nb, page){			
	var point = new GLatLng(lat_smos, lng_smos);			
	if(recherche == 'tec') zoom = 13;
	else if(recherche == 'etranger') zoom = 4;
	else if(recherche == 'paris') zoom = 12;
	else zoom = 7;	

	if(marker) map.panTo(point, zoom);
	else map.setCenter(point, zoom);			
	if(marker) marker.hide();			
	marker = new GMarker(point, markerOptions);
	map.addOverlay(marker);	
	
	marker.openInfoWindowHtml(contenuSmos, option_info);								
	GEvent.addListener(marker,"click", function() {
		marker.openInfoWindowHtml(contenuSmos, option_info);
	}); 

	if(numero == nb){
		page++;
		nb++;
		suivant = 1;
		update_flux(map,pays,recherche,nb,page,suivant);
	}
	return;			
}	


function visuSmos(contenu){	 				
	$.getJSON("scripts/codeSmos.php?idSmos="+contenu ,
		function(data){
			codeSmos = data.codeSmos;
			
			window.open("http://www.dilelui.com/smos.php?cd="+codeSmos);
		
		}
	);	
} 




/* function visuSmos(contenu){	 
	var avatarUser;					
 	var style_txt;
    $("#contenuBloc_flottant").html( '<div style=\"text-align:center; padding-top:15px; padding-bottom:15px; background-color:#fff;\"><img src="img/loader.gif" /></div>' );
	
	$.get("scripts/avatarSmos.php?idSmos="+contenu, function(avatar){
		if(avatar == 0 || avatar == '0' ){
           style_txt = "";
           avatarUser = "";
        }else{
            avatarUser = '<img src="'+avatar+'" />';
            style_txt = "float:left; width:240px; margin-left:10px;";
        }
				
        $.getJSON("scripts/contenuSmos.php?idSmos="+contenu ,
            function(data){
                if(data.sexeSmos == "F") var sexSmos = "<span style=\"color:#993399;\">une femme</span>";
                else var sexSmos = "<span style=\"color:#993399;\">un homme</span>";
                if(data.ageDebutSmos == 0) var ageDebSmos = "18";
                else var ageDebSmos = data.ageDebutSmos;
                if(data.ageFinSmos == 0) var ageFSmos = "100";
                else var ageFSmos = data.ageFinSmos;
				
                    if(data.commune != null) var contenuCommune = " "+data.commune; else var contenuCommune = "";

                    if(data.codePostal != null) var contenuCodePostal = " ("+data.codePostal+")"; else var contenuCodePostal = "";

                    if(data.departement != null) var contenuDepartement = " "+data.departement; else var contenuDepartement = "";

                    if(data.typeLpSmos != null && data.typeLpSmos != 'autre' && data.type2LpSmos != null && data.type3LpSmos != null) var contenuOu = data.typeLpSmos+", "+data.type2LpSmos+", "+data.type3LpSmos;
                    else if(data.typeLpSmos != null && data.typeLpSmos != 'autre' && data.type2LpSmos != null) var contenuOu = data.typeLpSmos+", "+data.type2LpSmos;
                    else if(data.typeLpSmos != null && data.typeLpSmos != 'autre' && data.type3LpSmos != null) var contenuOu = data.typeLpSmos+", "+data.type3LpSmos;
                    else if(data.typeLpSmos != null && data.typeLpSmos != 'autre') var contenuOu = data.typeLpSmos;
                    else var contenuOu = "";

                    if(contenuOu == '' && (contenuCommune != '' || contenuCodePostal != '' || contenuDepartement != '')){
						var contenuComplet = contenuCommune+contenuCodePostal+contenuDepartement;
					}else{
						var contenuComplet = contenuOu+contenuCommune+contenuCodePostal+contenuDepartement;
					}


                    var contenuVisuSmos = "<div class=\"text_info_modal\">"                                    
                                    + "<div style=\"color:#999966; font-weight:bold; float:left; clear:both; width:350px; margin-bottom:10px; \">"+contenuComplet+"</div>"
                                    + "<div style=\"float:left;\">"+avatarUser+"</div>"
                                    + "<div style=\""+style_txt+"\"><span class=\"gras\">Tu es "+sexSmos+", entre "+ageDebSmos+" et "+ageFSmos+" ans.<br /><br />"
                                    + data.detailSmos+"</span></div>"
                                    + "<div class=\"texteSmos\" style=\"width:350px;\">"+data.texteSmos+"</div><br /><br />"
                                    + "</div>";
							
									
				$("#contenuBloc_flottant").html( "<div id=\"arrondie_gauche\"></div>"+contenuVisuSmos+"<div id=\"arrondie_droite\"></div>" );
                $("#contenuBloc_flottant").fadeIn();
            }
        );
    });
		 
	setTimeout(function(){$("#overlayGlobal").css({ 'opacity' : '0.5', 'background-color' : '#000000' });},500);
	setTimeout(function(){document.getElementById("overlayGlobal").style.filter = "alpha(opacity=50)";},500);
	setTimeout(function(){$("#bloc_flottant").fadeIn();},550);
	
}  */


function testOuverture(){
	$("#overlayGlobal").css({ 'opacity' : '1'});
	$("#bloc_flottant").fadeOut();
}
	
function coupe_texte(chaine, taille){
	if(chaine.length > taille) var sous_chaine = chaine.substring(0,taille);
	else var sous_chaine = chaine;	
	return sous_chaine+"...";
} 


