//Icon Walibi:
var iconW = new GIcon();
iconW.image = "/images/content/google/marker_agrotechniek.png";
iconW.iconSize = new GSize(99, 88);
iconW.iconAnchor = new GPoint(60, 80);

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

function OnAddOverlayDirection(gdir) { 
	var i =0; 
	for(i =0; i< gdir.getNumGeocodes(); i++) { 
		map.removeOverlay(gdir.getMarker(i)); 
	} 
} 

function initialize() {
	if (GBrowserIsCompatible()) {      
		map = new GMap2(document.getElementById("map_canvas"));
		gdir = new GDirections(map, document.getElementById("directions"));
		map.setCenter(new GLatLng(52.440891, 5.763960), 8);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		GEvent.addListener(gdir, "load", onGDirectionsLoad);
		GEvent.addListener(gdir, "error", handleErrors);
		var marker1 = new GMarker(new GLatLng(52.434665, 5.760999), iconW);
		map.addOverlay(marker1);
		GEvent.addListener(gdir,"addoverlay", OnAddOverlayDirection);
	}
}

function setDirections(fromAddress, toAddress, locale) {
	//if (fromAddress!="") var fromAddress = ""+fromAddress+",Nederland";
	gdir.load("from: " + fromAddress + " to: " + toAddress, { "locale": locale });
}

function handleErrors(){
	if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		alert("Geen locatie gevonden voor het opgegeven adres. Controleer het adres en probeer het opnieuw.\n\nError code: " + gdir.getStatus().code);
	else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
		alert("Je verzoek kan op dit moment niet worden verwerkt. De exacte oorzaak van de storing is helaas niet bekend.\n\n Error code: " + gdir.getStatus().code);
	else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
		alert("De HTTP-Q parameter is onbekend of heeft geen waarde. Dit kan betekenen dat er geen adres is opgegeven.\n\n Error code: " + gdir.getStatus().code);
	else if (gdir.getStatus().code == G_GEO_BAD_KEY)
		alert("Ongeldige API Key voor gebruik van Google Directions op deze website.\n\n Error code: " + gdir.getStatus().code);
	else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
		alert("Je routebeschrijving kan niet met succes worden verwerkt.\n\n Error code: " + gdir.getStatus().code);
	else alert("Er is een onbekende fout opgetreden.");
}

function onGDirectionsLoad(){ 
	Show('show_options'); Show('show_directions');
	Hide('directions'); Hide('hide_directions'); Hide('show_print');
}

function print_route() {
	var a = window. open('','','scrollbars=yes,width=650,height=500');
	a.document.open("text/html");
	a.document.write('<html><head><title>Routebeschrijving naar Walibi World</title><style>BODY { margin: 20px; background-color: #FFFFFF; font-family: Arial, Helvetica, Sans-serif; font-size: 12px; line-height: 18px; font-weight: normal; font-variant: normal; text-align: left; } a { color: #000000; text-decoration: none; } tr, td, table { font-family: Arial, Helvetica, Sans-serif; font-size: 12px; line-height: 18px; font-weight: normal; font-variant: normal; text-align: left; } .class_directions { width: 590px; border: 1px solid #FFFFFF; color: #000000; background-color: #FFFFFF; } .class_map_canvas { margin-left: 5px; width: 579px; height: 400px; border: 1px solid #c0c0c0; overflow: hidden; }</style></head><body>');
	a.document.write('<p style="margin-left: 5px\"><strong>Routebeschrijving naar Walibi World</strong><br><br>Walibi World<br>Spijkweg 30<br>8256 RJ Biddinghuizen<br><br><a href="javascript:print();" style="text-decoration: underline;"><strong>Print deze routebeschrijving</strong></a></p>');
	a.document.write(document.getElementById('print_route').innerHTML);
	a.document.write('</body></html>');
	a.document.close();
	a.print();
}

