 //<![CDATA[
var map = null;
var geocoder = null;

function load() {
  if (GBrowserIsCompatible()) {

    // Map, controls and options
    opts={
      size:new GSize(650,500)
    }
    map = new GMap2(document.getElementById("map"),opts);
    map.setCenter(new GLatLng(49.526545456153805, 5.731086730957031), 14);
    map.addControl(new GSmallMapControl());
    
    GEvent.addListener(map, "moveend", function() {
  	var center = map.getCenter();
  	document.getElementById("message").innerHTML = center.toString();
		});

    // Geocoder (address -> coord)
    geocoder = new GClientGeocoder();

    // Marker for the city hall
    city_hall = addMarker(new GLatLng(49.520375, 5.712445),{title:"Mairie",icon:new GIcon(G_DEFAULT_ICON, "http://www.google.com/mapfiles/markerM.png")});
    addInfo(city_hall,
      "<b>Mairie de Cosnes-et-Romain</b><br />12, rue du Languedoc<br />Plus d'information sur la mairie sont disponibles<br /><a href=\"mairie.php\">sur cette page</a>."
    );

    // Marker for salle polyvalente
    salle_poly = addMarker(new GLatLng(49.520941, 5.715989),{title:"Salle Polyvalente Jean Monnet",icon:new GIcon(G_DEFAULT_ICON, "http://www.google.com/mapfiles/markerS.png")});
    addInfo(salle_poly,
      "<b>Salle Polyvalente Jean Monnet</b><br />60, rue du Dauphiné<br />"+
      "Tél. : 03 82 24 27 08"
    );
    
    // Marker for IUT
    iut = addMarker(new GLatLng(49.528051, 5.748539),{title:"IUT Henry Poincaré",icon:new GIcon(G_DEFAULT_ICON, "http://www.google.com/mapfiles/markerI.png")});
    addInfo(iut,
      "<b>IUT Henry Poincaré</b><br />186, rue de Lorraine<br />"+
      "Tél. : 03 82 39 62 00<br />"+
			"Télécopie : 03 82 39 62 90<br />"+
			"<a href=\"mailto:standard@iut-longwy.uhp-nancy.fr\">standard@iut-longwy.uhp-nancy.fr</a>"
    );
    
    // Marker for school
    school = addMarker(new GLatLng(49.518776, 5.715873),{title:"Ecole primaire de Cosnes-centre",icon:new GIcon(G_DEFAULT_ICON, "http://www.google.com/mapfiles/markerE.png")});
    addInfo(school,
      "<b>Ecole primaire de Cosnes-centre</b><br />13, rue d'Anjou<br />"+
      "Tél. : 03.82.24.90.69"
    );
    
    // Marker for school2
    school2 = addMarker(new GLatLng(49.527892, 5.73771),{title:"Groupe scolaire Victor Hugo",icon:new GIcon(G_DEFAULT_ICON, "http://www.google.com/mapfiles/markerE.png")});
    addInfo(school2,
      "<b>Groupe scolaire Victor Hugo</b><br />33, rue de Lorraine<br />"+
      "Tél. : 03.82.24.56.18"
    );
    
    // Marker for FEP Vaux
    fep = addMarker(new GLatLng(49.532807, 5.715529),{title:"Foyer des Jeunes et d'Education Populaire de Vaux",icon:new GIcon(G_DEFAULT_ICON, "http://www.google.com/mapfiles/markerF.png")});
    addInfo(fep,
      "<b>Foyer des Jeunes et d'Education Populaire de Vaux</b><br />22, rue d'Alsace<br />"+
      "Tél. : 03.82.23.35.66"
    );
    
    // Marker for pépinière d'entreprises
    pep = addMarker(new GLatLng(49.520557, 5.717581),{title:"Pépinière d'Entreprises",icon:new GIcon(G_DEFAULT_ICON, "http://www.google.com/mapfiles/markerP.png")});
    addInfo(pep,
      "<b>Pépinière d'Entreprises</b><br />4, rue Robert Schuman<br />"+
      "Tél. : 03.82.26.03.10<br />"+
      "Fax  : 03.82.26.03.11<br />"+
      "Courriel : <a href=\"mailto:syndicat.mixte@wanadoo.fr\">syndicat.mixte@wanadoo.fr</a>"
    );

  }
}


function addMarker(point, options) {
  marker = new GMarker(point , options);
  map.addOverlay(marker);
  return marker;
}


function addInfo(marker, text) {
  GEvent.addListener(marker, "click",
    function() {
      map.setCenter(marker.getPoint(),16);
      marker.openInfoWindowHtml(text);
    }
  );
}


function showAddress(address) {
  if (geocoder) {
    geocoder.getLatLng(
      address,
      function(point) {
        if (!point) {
          alert(address + " non trouvée.");
        }
        else {
          map.setCenter(point,16);
          var marker = new GMarker(point);
          map.addOverlay(marker);
          marker.openInfoWindowHtml(address);
          var center = map.getCenter();
          document.getElementById("message").innerHTML = center.toString();
        }
      }
    );
  }
}

//]]>
