var map1;
var map2;
var directionsService1 = new google.maps.DirectionsService();
var directionsService2 = new google.maps.DirectionsService();
var directionsDisplay;
var myLatlng1 = new google.maps.LatLng(53.420002, -2.331172); // Manchester
var myLatlng2 = new google.maps.LatLng(52.62188, 1.2968); // Norwich
var marker1 = new google.maps.Marker({ position: myLatlng1 });
var marker2 = new google.maps.Marker({ position: myLatlng2 });


function initialize() {
	directionsDisplay1 = new google.maps.DirectionsRenderer();
	directionsDisplay1.setMap(map1);
	directionsDisplay1.setPanel(document.getElementById("directions"));
	
	var myOptions1 = {
		zoom: 13,
		center: myLatlng1,
		disableDefaultUI: true,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	map1 = new google.maps.Map(document.getElementById("map-canvas-1"), myOptions1);
	marker1.setMap(map1);
	
	directionsDisplay2 = new google.maps.DirectionsRenderer();
	directionsDisplay2.setMap(map2);
	directionsDisplay2.setPanel(document.getElementById("directions"));
	
	var myOptions2 = {
		zoom: 13,
		center: myLatlng2,
		disableDefaultUI: true,
		unitSystem: google.maps.UnitSystem.IMPERIAL,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	map2 = new google.maps.Map(document.getElementById("map-canvas-2"), myOptions2);
	marker2.setMap(map2);
}

function calcRoute(map, start, end) {
	if (!start || start == 'Enter postcode') {
		alert("Please enter a postcode");
	}
	else {
		var start = start;
		var end = end;
		var request = {
			origin: start,
			destination: end,
			unitSystem: google.maps.UnitSystem.IMPERIAL,
			travelMode: google.maps.TravelMode.DRIVING
		};
		if (map == 1) {
			directionsDisplay1.setMap(map1);
			directionsService1.route(request, function(response, status) {
				if (status == google.maps.DirectionsStatus.OK) {
					directionsDisplay1.setDirections(response);
					$('#directions').html('');
				}
			});
		}
		else {
			directionsDisplay2.setMap(map2);
			directionsService2.route(request, function(response, status) {
				if (status == google.maps.DirectionsStatus.OK) {
					directionsDisplay2.setDirections(response);
					$('#directions').html('');
				}
			});
		}
	}
}

window.onload = initialize();


