﻿var sfgLatLong = new VELatLong(40.16614187588558, -104.97761607170105);
var map;
function GetMap() {
	map = new VEMap('myMap');
	map.SetDashboardSize(VEDashboardSize.Small);
	map.LoadMap(sfgLatLong, 13, 'r', false);
	var shape = new VEShape(VEShapeType.Pushpin, map.GetCenter());
	shape.SetTitle('<p style="text-align:left">The Spitfire Group</p>');
	shape.SetDescription('<p style="text-align:left">11409 Business Park Circle<br/>Suite 110<br/>Firestone, CO 80504<br/><br/>Office: (303)485-1880</p>');
	map.AddShape(shape);
	//map.ShowInfoBox(shape);
	$("#routeStepList li:odd").css("background-color", "#f6f1e6");

}
function SetCurrentRoute(routeNumber) {
	  var fromLatLong;
      var mapOptions = new VERouteOptions();
      mapOptions.SetBestMapView = false;
      mapOptions.RouteCallback = onGotDirections;
      
	if (routeNumber == 0) { // From Denver
	  fromLatLong = new VELatLong(40.1174300909042, -104.980078339577);
	  $('#routeTitleLabel').text("From Denver (via I-25 N)");
	} else if (routeNumber == 1) { // From Boulder
	  fromLatLong = new VELatLong(40.1604205369949, -105.013348460197);
	  $('#routeTitleLabel').text("From Boulder (via SR-119)");
	} else if (routeNumber == 2) { // From Fort Collins
	  fromLatLong = new VELatLong(40.213029384613, -104.980148077011);
	  $('#routeTitleLabel').text("From Fort Collins (via I-25 S)");
	} else {
	  fromLatLong = 0;
	  $('#routeTitleLabel').text("From " + routeNumber);
	}
	
	if (fromLatLong != 0 ) {
      map.GetDirections([fromLatLong, sfgLatLong], mapOptions);
    } else {
      map.GetDirections([routeNumber, sfgLatLong], mapOptions);
    }
    
    
}
function onGotDirections(route) {
	// Unroll the route
	var turns = "";
	var legs = route.RouteLegs;
	var leg = null;
	var turnNum = 0;
	
	for (var i = 0; i < legs.length; i++) {
		leg = legs[i];
		var turn = null;
		for (var j = 0 ; j < leg.Itinerary.Items.length; j++) {
			//turnNum++;
			turn = leg.Itinerary.Items[j];
			if (j == 0 ) {
				turns += "<li>" + turn.Text + "</li>";
		    } else {
		    	turns += "<li><div class='turnNumber'>" + j + ".</div><div class='turnText'>" + turn.Text + "</div></li>";
		    }
		}
	}
	$('#routeStepList').html(turns);
	$("#routeStepList li:odd").css("background-color", "#f6f1e6");
	
}
function ResetMap() {
	 $('#mapFromAddress').val("");
	 SetCurrentRoute(0);
	 map.SetCenter(sfgLatLong);
 	 map.DeleteRoute();
}

	  

