var markers_nb=0;
/* variables à paramétrer */
var latitude=0;	var longitude=0;	// reinit sur le centre de tous les points (mettre 0 SI un seul point)
var button_color = '#000000';
var button_backgroundColor = '#FFE97F';
var button_overBackgroundColor = '#FFD400';
var button_font = '11px Verdana';
var button_border = '1px solid #545454';
var button_width = '110px';
var map_zoom=10;// niveau de zoom de la carte
// contenu de la fenêtre d'info (ne pas modifier les variables %VARIABLE%)
var InfoWindowContent ='<div style="width:240px;font-size:11px;text-align:left;">' +
'<b>%NOMSOCIETE%</b><br />%ADRESSESOCIETE%<br />%CODEPOSTALSOCIETE% %VILLESOCIETE%' +
'<br />' +
'<form action="http://maps.google.com/maps" method="get" target="_blank" style="margin:0;padding;0">' +
'<table border="0" cellpadding="0" cellspacing="0">' +
'<tr><td colspan="2" style="font-size:10px;color:#B2B2B2;"><b>'+IW_txtitineraire+' : </b></td></tr>' +
'<tr><td colspan="2" style="font-size:10px;color:#B2B2B2;">'+IW_txtstartloc+'</td></tr>' +
'<tr><td valign="middle"><input type="text" name="saddr" id="saddr" value="" style="width:200px;height:20px;border:1px solid #B2B2B2;" /></td>' +
'<td valign="middle" style="padding-left:1px;"><input border="0" src="googlemap/bt_itineraire.gif" type="image"style="height:20px;cursor:hand;cursor:pointer;"></td></tr>' +
'</table>' +
'<input type="hidden" name="daddr" value="%LATCOORD%,%LNGCOORD%"/>'+
'</form>' +
'</div>';

/* -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - */
//<![CDATA[
	function load() {
		if (GBrowserIsCompatible()) {
		
		var baseIcon = new GIcon();
		baseIcon.iconSize=new GSize(12,20);
		baseIcon.shadowSize=new GSize(20,22);
		baseIcon.iconAnchor=new GPoint(6,20);
		baseIcon.infoWindowAnchor=new GPoint(5,1);
		var icon_type1 = new GIcon(baseIcon, 'googlemap/mm_20_red.png', null, 'googlemap/mm_20_shadow.png');

			GDownloadUrl("googlemap/googlemapdata.xml", function(data) {
				var FormulaireItineraire = [];
				var latcoord = [];
				var lngcoord = [];
				var couleurfond = [];
				var xml = GXml.parse(data);
				var markers = xml.documentElement.getElementsByTagName("marker");
					markers_nb = markers.length;
				for (var i = 0; i < markers_nb; i++) {
					latcoord[i] = parseFloat(markers[i].getAttribute("lat"));
					lngcoord[i] = parseFloat(markers[i].getAttribute("lng"));
					var point = new GLatLng(latcoord[i], lngcoord[i]);
					var type = markers[i].getAttribute("type");
						var ID_Marker = markers[i].getAttribute("id");
					var NomSociete = markers[i].getAttribute("nom");
					var AdresseSociete = markers[i].getAttribute("adresse");
					var CodePostalSociete = markers[i].getAttribute("codepostal");
					var VilleSociete = markers[i].getAttribute("ville");
					var Lien = markers[i].getAttribute("lien");

					// Couleur du fond du Formulaire Itineraire //
					if(type=='default'){couleurfond[i] = "#F3F4F5";}// non utilisé
				
					// Formulaire Itineraire //
					InfoWindowContent2=InfoWindowContent.replace("%NOMSOCIETE%", NomSociete);
					InfoWindowContent2=InfoWindowContent2.replace("%ADRESSESOCIETE%", AdresseSociete);
					InfoWindowContent2=InfoWindowContent2.replace("%CODEPOSTALSOCIETE%", CodePostalSociete);
					InfoWindowContent2=InfoWindowContent2.replace("%VILLESOCIETE%", VilleSociete);
					InfoWindowContent2=InfoWindowContent2.replace("%LIEN%", Lien);
					InfoWindowContent2=InfoWindowContent2.replace("%LATCOORD%", latcoord[i]);
					InfoWindowContent2=InfoWindowContent2.replace("%LNGCOORD%", lngcoord[i]);
					FormulaireItineraire[i] = InfoWindowContent2;

					var marker = createMarker(point,type,NomSociete,FormulaireItineraire[i]);
						
						// SI un seul point OU SI ID point égale ID passé en var GET ALORS afficher ce point
						if( (markers_nb == 1) || (ID_Marker == getID_Marker) ){
							MaCarte.setCenter(point, map_zoom);
							MaCarte.openInfoWindowHtml(MaCarte.getCenter(),FormulaireItineraire[i]);
						}
						if(markers_nb == 1){
							latitude=latcoord[i]; longitude=lngcoord[i];	// reinit sur le seul point
						}
						MaCarte.addControl(new SRBoutonControl());
					MaCarte.addOverlay(marker);
				}
			});
						
			// Fonction permettant la création du marker //
			function createMarker(point,type,nomsociete,itineraire) {
				if(type=='default'){var icone = icon_type1;} 
				var marker = new GMarker(point,{icon:icone, title:nomsociete});
				GEvent.addListener(marker, 'click', function() {
					//MaCarte.setCenter(point, 10); // centrer sur le point cliqué - ne pas le faire car cela n'est pas très fluide
					marker.openInfoWindowHtml(itineraire);
				});
				return marker;
			}

			// Fonction Réinitialiser la carte
			function SRBoutonControl() {}
			SRBoutonControl.prototype = new GControl();
			SRBoutonControl.prototype.initialize = function(MaCarte) {
				var containerSR = document.createElement('div');
				var boutonRestauration = document.createElement('div');
				this.setButtonStyle_Bis_(boutonRestauration);
				containerSR.appendChild(boutonRestauration);
				if(markers_nb == 1){	var button_text=button_text1;	}else{	var button_text=button_text2;	}
				boutonRestauration.appendChild(document.createTextNode(button_text));
				GEvent.addDomListener(boutonRestauration, 'click', function() {
					MaCarte.closeInfoWindow();// fermer toutes les fenêtres d'infos
					MaCarte.setCenter(new GLatLng(latitude,longitude), map_zoom);					
				});
				GEvent.addDomListener(boutonRestauration, 'mouseover', function() {
					this.style.backgroundColor = button_overBackgroundColor;
				});
				GEvent.addDomListener(boutonRestauration, 'mouseout', function() {
					this.style.backgroundColor = button_backgroundColor;
				});
				
				  MaCarte.getContainer().appendChild(containerSR);
				  return containerSR;
			}
			SRBoutonControl.prototype.getDefaultPosition = function() {
			  return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(7, 7));
			}
			SRBoutonControl.prototype.setButtonStyle_Bis_ = function(button) {
			  button.style.textDecoration = 'none';
			  button.style.color = button_color;
			  button.style.backgroundColor = button_backgroundColor;
			  button.style.font = button_font;
			  button.style.border = button_border;
			  button.style.padding = '2px';
			  button.style.marginBottom = '3px';
			  button.style.textAlign = 'center';
			  button.style.width = button_width;
			  button.style.cursor = 'pointer';
			}
			
			// Création de la carte et de ses contrôles //
			var MaCarte = new GMap2(document.getElementById('macarte'));
			MaCarte.addControl(new GSmallMapControl());
			MaCarte.addControl(new GMapTypeControl());
			
				MaCarte.setCenter(new GLatLng(latitude,longitude), map_zoom);

		}else{
			alert('Malheureusement, votre navigateur n\'est pas compatible avec Google Maps');
		}
	}
new Event.observe(window, 'load', load);
new Event.observe(window, 'unload', GUnload);
//]]>
