var map;
var directionsPanel;
var directions;
var cadIcon;

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

	var cadPoint1 = new GLatLng(49.131,-66.4873);

	map.setCenter(cadPoint1, 13);
	map.setMapType(G_NORMAL_MAP);
	map.addControl(new GSmallZoomControl());
	map.addControl(new GMapTypeControl());
	map.enableDoubleClickZoom();
	map.enableContinuousZoom();

	myKBHandler = new GKeyboardHandler(map);
	
/*	icon1 = new GIcon();
	icon1.image = "/images/ul/icones/pointeur_google.png";
	icon1.iconSize = new GSize(39,42);
	icon1.iconAnchor = new GPoint(30,30);
	icon1.infoWindowAnchor = new GPoint(5, 1);
	
			
	marker1 = new GMarker(cadPoint1, icon1);*/
	
	marker1 = new GMarker(cadPoint1);
	
	directionsPanel = document.getElementById("directions");
	directions = new GDirections(map, directionsPanel);

	map.addOverlay(marker1);
	
	GEvent.addListener(directions, "load", onGDirectionsLoad);

  }
}

function getDirections(from, to){
	dirString = "from: "+from+" to: 49.131,-66.4873";
	directions.load(dirString);
}

function onGDirectionsLoad(){	
	document.getElementById("directions").style.display = "block";
	map.setMapType(G_NORMAL_MAP);
	/* si nécessaire
	map.removeOverlay(marker1);*/
}

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

$(function(){
	if ( $('#map_container').length > 0  ) {
		loadMap();
	}
})
