// Interface Google Maps
var Sites = new creerSites();

//	Variables globales
var Texte, Latitude, Longitude, Zoom;
var Map = null;

function creerSites() {
	this.Sites = new Array();
	this.ajouter = ajouterSite;
	this.lister = listerSites;
}

function ajouterSite(Nom, Adresse, Latitude, Longitude) {
	var Site = new Object();
	Site.Nom = Nom;
	Site.Adresse = Adresse;
	Site.Latitude = Latitude;
	Site.Longitude = Longitude;
	this.Sites[this.Sites.length] = Site;
}

function listerSites() {
	for (var n = 0; n < this.Sites.length; n++) {
		with (document) {
			write('<div class="Adresse">');
			write(this.Sites[n].Nom + '<br />' + this.Sites[n].Adresse);
			write('</div>');
			write('<div class="Panneau">');
			write('<a href="#" onClick=\'PopUpMap("GVE<br />' + this.Sites[n].Nom + '<br />' + this.Sites[n].Adresse + '", ' + this.Sites[n].Latitude + ', ' + this.Sites[n].Longitude + ');return false;\'></a>');
			write('</div>');
		}
	}
}

function PopUpMap(Texte, Latitude, Longitude) {
	var LargeurFenetre = 800 + 15;
	var HauteurFenetre = 600 + 15;
	var Left = (window.screen.width - LargeurFenetre) / 2;
	var Top = (window.screen.height - HauteurFenetre) / 2;
	var Page = "Map.html?T=" + Texte + "&X=" + Latitude + "&Y=" + Longitude + "&Z=" + 16;
	var Configuration = "dependent=yes,left=" + Left + ",top=" + Top +
		",width=" + LargeurFenetre + ",height=" + HauteurFenetre +
		",resizable=no,directories=no,location=no,menubar=no,scrollbars=no,statusbar=no,toolbar=no";
	if (Map != null) if(! Map.closed) Map.close();
	Map = window.open(Page, 'Map', Configuration);
	Map.focus();
}

function getParam() {
	var Parametres = window.location.search.substring(1).split("&");
	var Parametre = new Array(1), n;
	for (n = 0; n < Parametres.length; n++) {
		Parametre = Parametres[n].split("=");
		switch (Parametre[0]) {
			case ("T") :
				Texte = Parametre[1];
				break;
			case ("X") :
				Latitude = Parametre[1];
				break;
			case ("Y") :
				Longitude = Parametre[1];
				break;
			case ("Z") :
				Zoom = Parametre[1];
				break;
		}
	}
}

function displayMap(Texte, Latitude, Longitude, Zoom) {
	if (GBrowserIsCompatible()) {
		// affiche la carte centrée sur les coordonnées
		var map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(Latitude, Longitude ), 16);
		map.setMapType(G_NORMAL_MAP);

		// affiche le grand curseur de zoom
		map.addControl(new GLargeMapControl());
		// affiche le petit curseur de zoom
// 	map.addControl(new GSmallMapControl());
		// affiche les petits boutons de zoom
// 	map.addControl(new GSmallZoomControl());
		// affiche l'échelle
		map.addControl(new GScaleControl());
		// affiche le selecteur de mode
		map.addControl(new GMapTypeControl());
		// affiche la petite carte de situation
		map.addControl(new GOverviewMapControl());
 
		// ces lignes définissent le point et sa légende
		var point = new GLatLng(Latitude, Longitude);
		var marker = new GMarker(point);
		map.addOverlay(marker);
		// affiche l'info bulle légende
		marker.openInfoWindowHtml(unescape(Texte));
		// évennement d'affichage de l'info bulle légende
		GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(unescape(Texte));});
	}
}

