var map;
var directionsPanel;
var directions;
var mqcIcon;

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

	var mqcPoint = new GLatLng(46.3442,-72.5393);

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

	myKBHandler = new GKeyboardHandler(map);
	
	mqcIcon = new GIcon();
	mqcIcon.image = "http://culturepop.qc.ca/images/i_graphiques/pinmqc.png";
	mqcIcon.shadow = "http://culturepop.qc.ca/images/i_graphiques/pinombre.png";
	mqcIcon.iconSize = new GSize(70, 42);
	mqcIcon.shadowSize = new GSize(70, 42);
	mqcIcon.iconAnchor = new GPoint(25, 42);
	mqcIcon.infoWindowAnchor = new GPoint(5, 1);
	
	marker01 = new GMarker(mqcPoint, mqcIcon);
	//marker01 = new GMarker(mqcPoint);

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

	map.addOverlay(marker01);
	GEvent.addListener(directions, "load", onGDirectionsLoad);
	//GEvent.addListener(directions, "error", onGDirectionsError);
  }
}

function getDirections(from){
	//dirString = "from: "+from+" to: 200 Rue Laviolette, Trois-Rivieres, QC, Canada";
	dirString = "from: "+from+" to: 46.3442,-72.5393";
	directions.load(dirString);
}

function onGDirectionsLoad(){
	//$("#directions").show();
	document.getElementById("directions").style.display = "block";
	map.setMapType(G_NORMAL_MAP);
}

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