var directionDisplay;
var directionsService = new google.maps.DirectionsService();

function googlemaps_initialize() {
	directionsDisplay = new google.maps.DirectionsRenderer()
	
	var myOptions = {
		zoom: 13,
		center: new google.maps.LatLng(51.39577, 5.98567),
		disableDefaultUI: true,
		navigationControl: true,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
	var myLatLng = new google.maps.LatLng(51.39577, 5.98567);
	
	var image = new google.maps.MarkerImage('/public/img/logo-route.png');

	new google.maps.Marker({
		position: myLatLng,
		map: map,
		icon: image,
		title: "Toverland"
	});
	directionsDisplay.setMap(map);
	directionsDisplay.setPanel(document.getElementById("directionsPanel"));
}

function googlemaps_calcRoute() {
	StartLocation = document.getElementById('fromAddress').value;
	var start = StartLocation; 
	var end = "Toverland, Sevenum";
	var request = {
		origin:start, 
		destination:end,
		travelMode: google.maps.DirectionsTravelMode.DRIVING
	};
	directionsService.route(request, function(response, status) {
		if (status == google.maps.DirectionsStatus.OK) {
			directionsDisplay.setDirections(response);
		}
	});
	return false;
}

$(document).ready(function(){
	
	$('#map_canvas').each(function(){
		googlemaps_initialize();
	});
	
	$('#plan_route').click(function(){
		googlemaps_calcRoute();
	});
});
