﻿var map = null;
var location1;
$(function() {
    GetMap();
});

function GetMap() {
    map = new VEMap('mymapdiv');
    map.LoadMap(new VELatLong(53.260823448005645, -2.12994754314421), 11, 'r', false);
    location1 = AddPin(new VELatLong(53.260823448005645, -2.12994754314421), "LUX interior", "88-90 Chestergate<br/> Macclesfield<br/> Cheshire<br/> United Kingdom<br/> SK11 6DU<br/> Tel:01625 439200");
}
function AddPin(point, title, description) {
    var pin = map.AddPushpin(point);
    pin.SetTitle(title);
    pin.SetDescription(description);
    return pin;
}
function SelectLocation(location) {
    var pin = map.AddPushpin(point);
    pin.SetTitle(title);
    pin.SetDescription(description);
    return pin;
}
function GetDirections() {
    document.getElementById("divShowDirections").innerHTML = "Calculating Route, Please Wait...";
    var options = new VERouteOptions();
    options.RouteCallback = onGotRoute;
    options.DrawRoute = true;
    var postcode = document.getElementById("postcode").value;
    map.GetDirections([postcode, new VELatLong(53.260823448005645, -2.12994754314421)], options);
}
function onGotRoute(route) {
    // Unroll route
    var legs = route.RouteLegs;
    var turns = "<p>Total distance: " + route.Distance.toFixed(1) + " mi</p>";
    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)<br />";
        }
    }
    document.getElementById("divShowDirections").innerHTML = turns.replace("\n", "<br/>");
    //$("#print").show();
}