// variable globales
var map = '';
var map2 ='';

//fonction qui r�encode les texte
function HTMLEncode(wText){
if(typeof(wText)!="string"){
wText=wText.toString();};
wText=wText.replace(/&/g, "&amp;") ;
wText=wText.replace(/"/g, "&quot;") ;
wText=wText.replace(/</g, "&lt;") ;
wText=wText.replace(/>/g, "&gt;") ;
wText=wText.replace(/'/g, "&#146;") ;
return wText;};


// fonction qui cr�� le marker, on defini dedans les event listener etc...
function createMarker(point, donnees,information_survol,img,taille_icone) {
       var blueIcon = new GIcon(G_DEFAULT_ICON);
	blueIcon.image = img;
	
	//on fait un switch pour affecter la taille de l'icone
	switch(taille_icone)
	{
		case "petit" :
			blueIcon.iconSize = new GSize(12, 21);	
			break;
		case "moyen" :
			blueIcon.iconSize = new GSize(18, 32);
			break;
		case "grand" :
			blueIcon.iconSize = new GSize(21, 41);
			break;
	} 
	// on efface l'ombre par default
	blueIcon.shadowSize = new GSize(0, 0);
	
	// on definit les option qui seront utilis� pour l'instanciation
	markerOptions = { icon:blueIcon };
	// on instancie par le constructeur en precisant les coordonn�es et les options du marker
        var marker = new google.maps.Marker(point, markerOptions);
      // action sur l'evement mouseover sur le marker
      	GEvent.addListener(marker, "mouseover", function() {
		// on affiche une petite fenetre d'information
		marker.openInfoWindowHtml(information_survol +"  <br> Cliquez sur l'icone pour plus de d&eacute;tails");
      });
      // action sur l'evement mouseout sur marker
            	GEvent.addListener(marker, "mouseout", function() {
      });
      // on associe le contenu de la fenetre du point au donn�es complementaires totales
      marker.bindInfoWindow(donnees);
      return marker; // on retourne le marker
    }
    



function initialize(nom_div) {
   if (GBrowserIsCompatible()) {
	geocoder = new GClientGeocoder(); // on declare le client coder
	map = new GMap2(document.getElementById(nom_div)); // on instancie la carte
	//on ajoute des controle a la carte
	map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
	map.setMapType(G_SATELLITE_MAP);
		
	
	// on centre la carte
	map.setCenter(new GLatLng(46.6424554,2.2817159), 5); 
	// action si on sort de la carte
	GEvent.addListener(map, "mouseout", function() {
	map.closeInfoWindow();//on ferme toute les fenetres des marker
      });
      } else { alert("navigateur incompatible");}
    }


    
function initialize2(nom_div) {
      if (GBrowserIsCompatible()) {
	
	map2 = new GMap2(document.getElementById(nom_div)); // on instancie la carte
	//on ajoute des controle a la carte
	map2.addControl(new GLargeMapControl());
        map2.addControl(new GMapTypeControl());
	
	
	// on centre la carte
	map2.setCenter(new GLatLng(48.856583,2.344208), 11); 
	// action si on sort de la carte
	GEvent.addListener(map, "mouseout", function() {
	map2.closeInfoWindow();//on ferme toute les fenetres des marker
      });
      } else { alert("navigateur incompatible");}
    }
    
    
//fonction qui retourne un marker a partir d'un adresse, 
//elle utilise un geocoder pour passer d'une adresse a des coordon� gps, 
//elle apelle aussi la fonction create marker pour faire des marker personnalis�

function showAddress(nom_actif,address,departement,information,information_survol,lien_pdf,icone,taille_icone) {

	var parts = address.split(',');
	var point = new GLatLng(parts[0], parts[1]);
	(function(point) {
		if (!point) {
			  alert(address +" - " + departement + " inconnu");
		 } else {
			  var marker = createMarker(point,information,information_survol,icone,taille_icone); // on apelle la fonction createMarker pour personnalis� le markner
			  map.addOverlay(marker); // on ajoute a la carte le markers
			  var marker2 = createMarker(point,information,information_survol,icone,taille_icone); // on apelle la fonction createMarker pour personnalis� le markner
			  map2.addOverlay(marker2); // on ajoute a la carte le markers
			 
			  document.getElementById("liste_actif").innerHTML= document.getElementById("liste_actif").innerHTML + "<li><a href='"+lien_pdf+"' onmouseover='centrer(new GLatLng"+ point +",\""+ HTMLEncode(information_survol)+"\","+ departement +" );'> "+HTMLEncode(nom_actif)+"</a> </li>";
		}
	})(point);
}
	

function centrer(point,information_survol,departement){

if(departement==75||departement==91||departement==92||departement==77||departement==93||departement==94||departement==95||departement==78){
	//map2.setCenter(point,11);
	map2.openInfoWindowHtml(point, information_survol+"<br> Cliquez sur l'icone pour plus de d&eacute;tails",{pixelOffset: new GSize(0,-30)});
}
else
{
	map2.closeInfoWindow();
}
//map.setCenter(point,5);
map.openInfoWindowHtml(point, information_survol+"<br> Cliquez sur l'icone pour plus de d&eacute;tails",{pixelOffset: new GSize(0,-30)});


}
