var map;
var gdir;
var geocoder = null;
var addressMarker;
var point;

function initialize() 
{
	if (GBrowserIsCompatible()) 
	{      
		map = new GMap2(document.getElementById("map"));
		gdir = new GDirections(map, document.getElementById("route"));
		//GEvent.addListener(gdir, "load", onGDirectionsLoad);
		//GEvent.addListener(gdir, "error", handleErrors);
		var point = new GLatLng(51.38708, 4.90891);
        map.setCenter(point, 13);
		var icon = new GIcon(G_DEFAULT_ICON);
      	icon.image = "/design/images/layout/h1_icon.png";
		icon.iconSize = new GSize(23, 22);
		icon.shadow = null;
		icon.iconAnchor = new GPoint(4,2)

      	var markerOptions = { icon:icon };
      	map.addOverlay(new GMarker(point,markerOptions));								
	}
}

function planRoute(fromAddress) 
{	
	//document.getElementById('routebeschrijving').style.display = 'none';
	map.clearOverlays();
	locale = 'nl_NL';
	toAddress = 'Mechelsevest 90, 3000 Leuven';
	gdir.load("from: " + fromAddress + " to: " + toAddress, { "locale": locale });		
}

function handleErrors()
{
	document.getElementById('routebeschrijving').style.display = 'none';
	if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		alert("Het opgegeven adres kon niet teruggevonden worden, dat kan te wijten zijn aan het feit dat het een recent of onjuist adres is");
	else if (document.getElementById("van").value=="")
		alert('Gelieve een adres op te geven...');
	else 
		alert("Een onbekende fout is opgetreden");
}

function onGDirectionsLoad()
{
	//document.getElementById('routebeschrijving').style.display = 'block';
	setTimeout(function() {
		document.getElementById('route').firstChild.firstChild.firstChild.firstChild.style.background = '#f2efe9';
		document.getElementById('route').firstChild.firstChild.firstChild.firstChild.style.border = '1px solid #7B604C';
		document.getElementById('route').firstChild.firstChild.lastChild.style.color = '#7B604C';
		document.getElementById('route').firstChild.firstChild.lastChild.previousSibling.firstChild.style.background = '#f2efe9';
		document.getElementById('route').firstChild.firstChild.lastChild.previousSibling.firstChild.style.border = '1px solid #7B604C';
		//document.getElementById('route').firstChild.firstChild.firstChild.firstChild.nextSibling.firstChild.style.fontWeight='bold';
		//document.getElementById('route').firstChild.firstChild.firstChild.firstChild.nextSibling.firstChild.style.color='#7B604C';
	}, 10);
}

$(document).ready(function() {
	if(typeof(GBrowserIsCompatible)!='undefined')
		initialize();
});
