﻿
//THIS FILE INJECTED DYNAMICALLY BY /neighborhood/usercontrols/PAGEHEADER.ascx
//menuMap is a global since we will need to access it.


var mmarray = mmarray || [];
var mmpinID = 0, mmoffices = null, nhoodcustomicon = "<img src='/images/JacksonHewittLogoIcon.gif' />", mmcenter = null, zoom = 12, menuMap = null;


function initMaps(elt, mmmap) {
    var interval = setInterval(function () {
        if ((eval("typeof VEMap") != "undefined")
            && (document.getElementById(elt).attachEvent != undefined))
        { clearInterval(interval); setNHoodMaps(elt, mmmap); }
    }, 10);
}

function setNHoodMaps(elt, mmmap) {

    if (officeJson != undefined) {
        mmoffices = $.parseJSON(officeJson);

        if (mmmap == null) {
            mmmap = new VEMap(elt);
            mmmap.SetDashboardSize(VEDashboardSize.Tiny);
            mmmap.LoadMap();
            mmmap.SetCenterAndZoom(mapstartpoint, zoom);
            if (elt == 'mmMap') {
                mmarray.push(mmmap); //inject this into the array. its the way we can figure out if the menu has been added to the page already. we can't
                //return the object because of lazy loading issues in FF.
            }
        }
        var numPins = 3;
        onMMFind(mmmap);
        //mmmap.Find(null, mapstartpoint, VEFindType.Business, null, 0, numPins, true, false, true, true, onMMFind);
        
    }
}


function onMMFind(mmmap) {
    var linkTarget = '/OfficeLocator/Office/?office=';

    mmcenter = mmmap.GetCenter();
    if (mmcenter == null || mmcenter.Latitude == null || mmcenter.Longitude == null) {
        return;
    }
    else {
        mmmap.DeleteAllPushpins();

        for (var i = 0; i < mmoffices.length; i++) {
            var loc = new VELatLong(mmoffices[i].Latitude, mmoffices[i].Longitude);
            var directions_button = "<a href='" + linkTarget + mmoffices[i].OfficeNumber + "' id='info' class='office_information'/>More Info</a>"

            var pin = new VEShape(VEShapeType.Pushpin, loc);
            pin.SetTitle(buildPinInfo(mmoffices[i]));
            pin.SetDescription(directions_button);
            pin.SetCustomIcon(nhoodcustomicon);
            mmmap.AddShape(pin);
        }

        if (mmoffices.length > 0) {
            mmmap.SetCenterAndZoom(new VELatLong(mmoffices[0].Latitude, mmoffices[0].Longitude), 14);
        }


    }

}

function buildPinInfo(office) {
    var fullAddress = "<div class='locator_map_left_navitem_expanded'><div id='locator_map_left'><p class='address_01'>" + "Office#" + office.pCenter + office.OfficeNumber + "</p><BR /><p class='address_01'>" + office.Address1 + " " + (office.Address2 != '' ? office.Address2 + "<br/> " : "<br/>") + office.City + ", " + office.State + " " + office.Zip + "</p>";

    return fullAddress;

}

