/* Tour Map Locations Script with Google Maps */

	var directionDisplay;
	var directionsService = new google.maps.DirectionsService();
	var map;

	function initialize() {
	  directionsDisplay = new google.maps.DirectionsRenderer();
	  var italy = new google.maps.LatLng(41.87194,12.56738);
		
	  var myOptions = {
	    zoom:5,
		mapTypeControl: true,
		mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},	
	    mapTypeId: google.maps.MapTypeId.ROADMAP,
	    center: italy
	  }
	
	  map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
	  directionsDisplay.setMap(map);
	
	  var start = document.gmap_start;
	  var end = document.gmap_end;
		
	  var points = [];
	  points = document.gmap_points;
	
	  calcRoute( start, end, points );
	}
	
	function calcRoute( start, end, points ) {
	  var waypts = [];	
	  var wyptArray = [];
		wyptArray = points;
	
	  for (var i = 0; i < wyptArray.length; i++) {
      	waypts.push({location:wyptArray[i]});
	  }

	  var request = {
	      origin: start, 
	      destination: end,
	      waypoints: waypts,
	      travelMode: google.maps.DirectionsTravelMode.DRIVING
	  };
	
	  directionsService.route(request, function(response, status) {
	    if (status == google.maps.DirectionsStatus.OK) {
	      directionsDisplay.setDirections(response);
	      var trip = response.trips[0];
	    }
	  });
	}