﻿/// <reference path="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1" />

var map = null;                  
var shape = null;

function loadMap()         
{         
    map = new VEMap('storeMap'); 
    map.SetDashboardSize(VEDashboardSize.Small);            
    map.LoadMap();                     
    var options = new VERouteOptions();            
    options.RouteCallback = onGotRoute;            
    //map.GetDirections(["1430 Buffalo-Mech Rd, Dawson IL 62520"], options);     
    map.Find(null, "1430 Buffalo-Mech Rd, Dawson IL 62520");  
    var loc = new VELatLong(39.823801, -89.406227);
    shape = new VEShape(VEShapeType.Pushpin, loc);
    map.AddShape(shape);
}         

function onGotRoute(route)         
{           
    // Unroll route           
    var legs= route.RouteLegs;           
    var turns    = "Total distance: " + route.Distance.toFixed(1) + " mi\n";           
    var numTurns = 0;           
    var leg      = null;           
    // Get intermediate legs            
    for(var i = 0; i < legs.length; i++)            
    {               
        // Get this leg so we don't have to derefernce multiple times               
        leg = legs[i];  // Leg is a VERouteLeg object                                 
        // Unroll each intermediate leg               
        var turn = null;  
        // The itinerary leg                                 
        for(var j = 0; j < leg.Itinerary.Items.length; j ++)               
        {                  
            turn = leg.Itinerary.Items[j];  
            // turn is a VERouteItineraryItem object                  
            numTurns++;                  
            turns += numTurns + ".\t" + turn.Text + " (" + turn.Distance.toFixed(1) + " mi)\n";               
        }            
    }            
    //alert(turns);         
}
