﻿//jquery 1.2.6 doesn't provide support to getScript from the local cache
//we need to add this ourselves currently
$.getScript = function(url, callback, cache) {
    $.ajax({
        type: "GET",
        url: url,
        success: callback,
        dataType: "script",
        cache: cache
    });
};

//our global map object
var map;

$(document).ready(function() {
    // This event is fired when the DOM is fully loaded
    // Is this browser supported by VE? If not why bother loading a broken control?
    if (!($.browser.msie) && !($.browser.mozilla) && !($.browser.safari)) {
        $("#mymap").html("Virtual Earth is not supported by your browser.")
    } else {
        // set a nice animated gif to show the map is loading
        $("#mymap").addClass("maploading");
        if (!($.browser.msie)) {
            //work around for non ie
            $.getScript("http://dev.virtualearth.net/mapcontrol/v6.2/js/atlascompat.js", "", true);
        }
        $.getScript("http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&onScriptLoad=onscriptload", "", true);
    }
});

function onscriptload() {
    // get rid of our load animation
    $("#mymap").removeClass("maploading");
    //load the map
    map = new VEMap('mymap');
    map.onLoadMap = onMapLoaded;
    map.LoadMap(new VELatLong(-27.47, 153.03), 16, VEMapStyle.Hybrid);
    //do nothing more to the map here, use the onMapLoaded event.
}

function onMapLoaded() {
    //here we can do what we want with the map object, add data etc.
}

$(window).unload(function() {
    // This event is fired when the web page is closing
    // Time to dispose our map
    if (map) map.Dispose();
});
