﻿

/* START : DIRECTIONS CONTENTE PAGE - SCRIPT CONTENT */
var AvarDirections = null;
function initDirectionsContent() {
    AvarDirections = {
      // HTML Nodes
      mapContainer: document.getElementById('directions-map-container'),
      fromInput: document.getElementById('from-input'),
      toInput: document.getElementById('to-input'),
     
      
      // API Objects
      dirService: new google.maps.DirectionsService(),
      dirRenderer: new google.maps.DirectionsRenderer(),
      map: null,
     
      
      showDirections: function(dirResult, dirStatus) {
        if (dirStatus != google.maps.DirectionsStatus.OK) {
          alert('Directions failed: ' + dirStatus);
          return;
        }
     
        // Show directions
        AvarDirections.dirRenderer.setMap(AvarDirections.map);
        AvarDirections.dirRenderer.setDirections(dirResult);
      },
     
      
      getSelectedTravelMode: function() {
        //var value = AvarDirections.travelModeInput.options[AvarDirections.travelModeInput.selectedIndex].value;
	    var value = 'driving';
        if (value == 'driving') {
          value = google.maps.DirectionsTravelMode.DRIVING;
        } else if (value == 'bicycling') {
          value = google.maps.DirectionsTravelMode.BICYCLING;
        } else if (value == 'walking') {
          value = google.maps.DirectionsTravelMode.WALKING;
        } else {
          alert('Unsupported travel mode.');
        }
        return value;
      },
     
      
      getSelectedUnitSystem: function() {
        //return AvarDirections.unitInput.options[AvarDirections.unitInput.selectedIndex].value == 'metric' ? google.maps.DirectionsUnitSystem.METRIC : google.maps.DirectionsUnitSystem.IMPERIAL;
	    return google.maps.DirectionsUnitSystem.IMPERIAL;
      },
     
     
      getDirections: function() {
	    var fromStr = AvarDirections.fromInput.value;
	    var toStr = AvarDirections.toInput.value;
        var dirRequest = {
          origin: fromStr,
          destination: toStr,
          travelMode: AvarDirections.getSelectedTravelMode(),
          unitSystem: AvarDirections.getSelectedUnitSystem(),
          provideRouteAlternatives: true
        };
        AvarDirections.dirService.route(dirRequest, AvarDirections.showDirections);
      },
     
      
      init: function() {
        var latLng = new google.maps.LatLng(51.60206895963152, -0.19351618862151554);
        AvarDirections.map = new google.maps.Map(AvarDirections.mapContainer, {
          zoom: 13,
          center: latLng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        });
    	
	    /*var marker = new google.maps.Marker({
		    position: AvarDirections.latlng, 
		    map: AvarDirections.map,
		    title:"Sandbox Mídias Interativas"
	    });*/
     
        // Show directions onload
        //AvarDirections.getDirections();
      }
    };
    
    AvarDirections.init();
}
/* END : DIRECTIONS CONTENTE PAGE - SCRIPT CONTENT */


