﻿/// <reference name="MicrosoftAjax.js" />
/// <reference path="~/scripts/jquery-1.4.1-vsdoc.js" />
/// <reference path="~/scripts/common.js" />

var map2 = null;

$(function() {
    GetMap();
});

function GetMap() {
    map2 = new VEMap('bingMap');
    map2.AttachEvent("onerror", mapError);

    map2.SetCredentials(bingAPIKey);
    map2.LoadMap(new VELatLong(32, -92.504883), 8, VEMapStyle.Road, false, VEMapMode.Mode2D, true, 0, null);
    map2.onLoadMap = addMarkers();
}

function mapError(mapEvent) {
    alert(mapEvent.error);
}

function addMarkers() {
    map2.ClearInfoBoxStyles();
    var arrTourismBureauDetails = $(":hidden[id$=hidMapData]").val().split('^');
    var arrTourismBureauInfo;
    var tourismBureauHtml;
    /*
    0 = Parish Name
    1 = Main City List
    2 = Bureau Name
    3 = AddressLine1
    4 = AddressLine2
    5 = City
    6 = State Abbreviation
    7 = Postal Code
    8 = Website
    9 = Latitude
    10 = Longitude
    11 = Parish page url
    */

    for (i = 0; i < arrTourismBureauDetails.length; i++) {
        arrTourismBureauInfo = arrTourismBureauDetails[i].split('|');
        tourismBureauHtml = '<html><body><h1><a class="mapInfoLink" href="' + arrTourismBureauInfo[11] + '?parish=' + arrTourismBureauInfo[0] + '">' + arrTourismBureauInfo[0] + ' Parish</a></h1>';
        tourismBureauHtml += arrTourismBureauInfo[1] + '<br />';
        tourismBureauHtml += arrTourismBureauInfo[2] + '<br />';
        tourismBureauHtml += arrTourismBureauInfo[3] + '<br />';
        if (arrTourismBureauInfo[4].length > 0) {
            tourismBureauHtml += arrTourismBureauInfo[4] + '<br />';
        }
        tourismBureauHtml += arrTourismBureauInfo[5] + ', ';
        tourismBureauHtml += arrTourismBureauInfo[6] + ' ';
        tourismBureauHtml += arrTourismBureauInfo[7];
        if (arrTourismBureauInfo[8].length > 0) {
            tourismBureauHtml += '<br />' + '<a class="mapInfoLink" href="http://' + arrTourismBureauInfo[8] + '" target="_blank">' + arrTourismBureauInfo[8] + '</a>';
        }
        tourismBureauHtml += '</body></html>';
        var testMarker = new VEShape(VEShapeType.Pushpin, new VELatLong(arrTourismBureauInfo[9], arrTourismBureauInfo[10]));
        testMarker.SetCustomIcon("<img src='http://www.explorelouisiananorth.org/mapicon.png' class='mapIcon' />");
        testMarker.SetTitle(arrTourismBureauInfo[0] + " Parish, " + arrTourismBureauInfo[1]);
        testMarker.SetDescription(tourismBureauHtml);
        map2.AddShape(testMarker);
    }
}
