var directions = null
var directionDisplay;


$(document).ready(function() {
	if($('#map_canvas').length) {
		var map;
		var elevator;
		var myOptions = {
			zoom: 14,
			center: new google.maps.LatLng(52.6541, 4.7971),
			mapTypeId: 'terrain'
		};
		map = new google.maps.Map($('#map_canvas')[0], myOptions);
		var markers = [];
		
		// Add a listener for idle event and call getElevation on a random set of marker in the bound
		google.maps.event.addListener(map, 'idle', function()
		{
			// Create an ElevationService
			elevator = new google.maps.ElevationService();
			$.each(markers, function(key, value)
			{
				value.setMap(null);
			});
			// getting bounds of current location
			var boundBox = map.getBounds();
			var southWest = boundBox.getSouthWest();
			var northEast = boundBox.getNorthEast();
			var lngSpan = northEast.lng() - southWest.lng();
			var latSpan = northEast.lat() - southWest.lat();
			// adding 20 markers to the map at random locations
			var locations = [];
			
			var location = new google.maps.LatLng(52.6541, 4.7971);
			locations.push(location);
			
			// Create a LocationElevationRequest object using the array's one value
			var positionalRequest = {
				'locations': locations
			};
		
			elevator.getElevationForLocations(positionalRequest, function(results, status)
			{
				if (status === google.maps.ElevationStatus.OK)
				{
					$.each(results, function(key, value)
					{
						if (value.elevation < 0)
						{
							markers[key] = new google.maps.Marker({
								position: value.location,
								map: map,
							});
						}
						else
						{
							markers[key] = new google.maps.Marker({
								position: value.location,
								map: map,
							});
						}
					});
				}
			});
		});

		var directionsService = new google.maps.DirectionsService();
		directionsDisplay = new google.maps.DirectionsRenderer();
		directionsDisplay.setMap(map);
		
		var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">H¿genhaug</h1>'+
'<div id="bodyContent">'+
'<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>'+
'<p>Find your way here from:</p>'+
'<form action="index.html" onsubmit="calcRoute();return false;">'+
'<input type="text" id="start" value="prinsensgade 5, 9000">'+
'<input type="submit" value="Find directions"></form>'+
'</div>'+
'</div>';



	}
}); 
