// JavaScript Document
function addLoadEvent(func) { 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function') { 
		window.onload = func; 
	} else { 
		window.onload = function() { 
			if (oldonload) { 
				oldonload(); 
			} 
			func(); 
		} 
	} 
}

var apex;
              
function initialize() {
    directionsDisplay = new google.maps.DirectionsRenderer();
	apex = new google.maps.LatLng(51.5553160, -0.6151710);
    var myOptions = { zoom: 11, center: apex, mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU }};
    var map = new google.maps.Map(document.getElementById("mapdisplay"), myOptions);
    directionsDisplay.setMap(map);
  	directionsDisplay.setPanel(document.getElementById("directions"));
	directionsService = new google.maps.DirectionsService();
	
	var image = new google.maps.MarkerImage('/SiteImages/apexlogomap.png', new google.maps.Size(200, 40), new google.maps.Point(0,0), new google.maps.Point(16, 39));
	var marker = new google.maps.Marker({position: apex, icon: image});
 	google.maps.event.addListener(marker, 'click', function() {
		map.setCenter(apex);
      	map.setZoom(16);
    });
	marker.setMap(map);
}
 
 function calcRoute() {
  var start = document.getElementById("end").value;
  var end = "SL2 3QQ";
  var request = {
    origin:start, 
    destination:end,
    travelMode: google.maps.DirectionsTravelMode.DRIVING,
	unitSystem: google.maps.DirectionsUnitSystem.IMPERIAL
  };
  directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(response);
    }
  });
}
