google.load("maps", "2.x");

// Construction de la carte
function initialize(lat, lng, zoom, txt) {
	if (google.maps.BrowserIsCompatible()) {
	  var point = new google.maps.LatLng(lat, lng);
    var map = new google.maps.Map2(document.getElementById("map"));
    map.setCenter(point, zoom);
		map.addControl(new google.maps.LargeMapControl());		// Creates a control with buttons to pan in four directions, and zoom in and zoom out, and a zoom slider.
		map.addControl(new google.maps.ScaleControl());				// Creates a control that displays the map scale.
		map.addControl(new google.maps.MapTypeControl());			// Creates a control with buttons to switch between map types.
		map.addControl(new google.maps.OverviewMapControl());	// Creates a collapsible overview mini-map in the corner of the main map for reference location and navigation (through dragging).
		if (txt) {
			map.openInfoWindowHtml(point, txt);
		}
	}
	else {
		alert("Désolé, mais votre navigateur n'est pas compatible avec Google Maps");
	}
}

// Affichage du plan
function popMap(lat, lng, zoom, txt) {
  // Plan
	var mapSection = document.getElementById("mapSection");
	mapSection.style.display = "block";
  initialize(lat, lng, zoom, txt);

	// Lien "Imprimer le plan"
	var url = "http://maps.google.com/maps?f=q&amp;hl=fr&amp;ie=UTF8&amp;ll="+lat+","+lng+"&amp;z="+zoom+"&amp;om=1&amp;pw=2";
	var link = "<a href='"+url+"' target='_blank'>Imprimer le plan</a>";
	var printMapLink = document.getElementById("printMapLink");
  printMapLink.innerHTML = link;

	// Lien "Agrandir le plan"
	var largeMapLink = document.getElementById("largeMapLink");
  largeMapLink.innerHTML = "<a href='index.php?id=plan-acces&amp;no_cache=1&amp;tx_axdir_pi1[lat]="+lat+"&amp;tx_axdir_pi1[long]="+lng+"&amp;tx_axdir_pi1[zoom]="+zoom+"'>Agrandir le plan</a>";

	window.location.href = String(window.location).replace(/\#.*$/, "") + "#plan";
}

// Fermer le plan
function closeMap() {
	var mapSection = document.getElementById("mapSection");
	mapSection.style.display = "none";
}
