﻿


var map = null;
var itemArray = new Array();
function EventMapLoad() {

    for (i = 0; i < mapArray.length; i++) {

        if (mapArray[i].lat) {

            /*
            var theDate = new Date()
            theDate.setFullYear(mapArray[i].dateYear, mapArray[i].dateMonth, mapArray[i].dateDay);

            var today = new Date();
            var lastYearsDate = new Date();
            lastYearsDate.setFullYear(today.getFullYear() - 1, today.getMonth(), today.getDate());

            if (lastYearsDate > theDate) {
                pin = "map_pin_old";
            }
            else {
                pin = "map_pin";
            }
            */
            
            pin = "map_pin";

            var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(mapArray[i].lat, mapArray[i].long));
            //shape.id = "pin" + i;
            //shape.SetCustomIcon("<div class='" + pin + "' id=pin" + i + "><div class='text'></div></div>");
            shape.SetCustomIcon("<div class='" + pin + "'><div class='text'></div></div>");
            
            var description = "";
            if (mapArray[i].name.length) { description += mapArray[i].name + "<br>" };
            if (mapArray[i].company.length) { description += "<b>" + mapArray[i].company + "</b><br>" };
            if (mapArray[i].street.length) { description += mapArray[i].street + "<br>" };
            if (mapArray[i].street2.length) { description += mapArray[i].street2 + "<br>" };
            if (mapArray[i].suburb.length) { description += "<b>" + mapArray[i].suburb + "</b><br>" };
            if (mapArray[i].caseStudy.length) { description += "<a href='javascript:showCaseStudy(" + i + ")' class='map'>View Case Summary</a><br>" };
            if (mapArray[i].apologyImage) { description += "<a href='apology.aspx?letterId=" + i + "' class='map'>View Apology</a>" };

            shape.SetDescription(description);

            map.AddShape(shape);

            itemArray.push(shape);

        }
    }
}




function CreateMap() {

    map = new VEMap('myMap');
    map.onLoadMap = EventMapLoad;
    map.LoadMap(new VELatLong(-27.1373683597955844, 133.19824218749997), 4, VEMapStyle.Road);
    map.LoadMap();
    map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
    //map.Find(null, "2000 australia", null, null, null, null, null, null, false, true, LocFound);
}


function showCaseStudy(id) {

    Shadowbox.open({
        player: 'html',
        title: mapArray[id].company,
        content: '<div class="caseStudy">' + mapArray[id].caseStudy + '</div>',
        width: 400,
        height: 200
    });

    logClick("caseStudy" + id + ".aspx", mapArray[id].company);
    
};

function FindLoc() {
    try {
        map.Find(null, document.getElementById('searchInput').value + " australia", null, null, null, null, null, null, false, true, LocFound);
    }
    catch (e) {
        alert(e.message);
    }
}

function LocFound() {
    map.SetZoomLevel(10);
} 


