
var map;
var directionsPanel;
var directions;
var mapIcon;

function loadMap() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));

	var mapPoint = new GLatLng(49.098434,-34.574395);

	map.setCenter(mapPoint, 11);
	map.setMapType(G_NORMAL_MAP);
	map.addControl(new GSmallZoomControl());
	map.addControl(new GMapTypeControl());
	map.enableDoubleClickZoom();
	map.enableContinuousZoom();
	map.enableScrollWheelZoom();

	myKBHandler = new GKeyboardHandler(map);
	
	mapIcon = new GIcon();
	mapIcon.image = "http://www.fem-mauricie.ca/images/MarkerFEM.gif";
	mapIcon.shadow = "http://www.fem-mauricie.ca/images/MarkerOmbre.png";
	mapIcon.iconSize = new GSize(70, 42);
	mapIcon.shadowSize = new GSize(70, 42);
	mapIcon.iconAnchor = new GPoint(25, 42);
	mapIcon.infoWindowAnchor = new GPoint(5, 1);
	
	//markerOptions = { icon:mapIcon };
	
	marker01 = new GMarker(mapPoint, mapIcon);

	directionsPanel = document.getElementById("directions");
	directions = new GDirections(map, directionsPanel);

	var it = new GInfoWindowTab("FEM Mauricie",$('#infobulle').html());

	GEvent.addListener(marker01, "click", function() {
		marker01.openInfoWindowTabsHtml([it]);
	});
	map.addOverlay(marker01);
	GEvent.addListener(directions, "load", onGDirectionsLoad);
	//GEvent.addListener(directions, "error", onGDirectionsError);
  }
}

function setDirections(fromAddress, toAddress, locale) {
      directions.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
    }
    

function onGDirectionsLoad(){
	$("#directions").show();
	map.setMapType(G_NORMAL_MAP);
}

function onGDirectionsError(){
	$("#directions").show();
	console.log(directions.getStatus());
}