/* Minification failed. Returning unminified contents.
(322,16-17): run-time error JS1195: Expected expression: .
(322,43-51): run-time error JS1010: Expected identifier: function
(322,53-54): run-time error JS1195: Expected expression: )
(322,55-56): run-time error JS1006: Expected ')': {
(326,10-11): run-time error JS1195: Expected expression: )
(328,17-18): run-time error JS1195: Expected expression: .
(328,54-55): run-time error JS1195: Expected expression: )
(328,56-57): run-time error JS1004: Expected ';': {
(332,10-11): run-time error JS1195: Expected expression: )
(334,97-98): run-time error JS1004: Expected ';': {
(352,10-11): run-time error JS1195: Expected expression: )
(354,63-64): run-time error JS1004: Expected ';': {
(394,7-8): run-time error JS1002: Syntax error: }
(857,3-4): run-time error JS1002: Syntax error: }
(860,40-41): run-time error JS1004: Expected ';': {
(873,3-24): run-time error JS1018: 'return' statement outside of function: return visibleMarkers
 */
$(document).ready(function () {
  $('#filterLocationTypes').on('change', function () {
    var filterLocationTypes = $(this).val();
    var filterLocationTypeId = $('div[id="' + filterLocationTypes + '"]');
    var supplementalSelects = $('.jsLocSupplemental');

    if (filterLocationTypeId.length > 0) {
      supplementalSelects.hide();
      filterLocationTypeId.show();
    } else {
      supplementalSelects.hide();
      supplementDropdownValue = '';

      $('.jsLocSupplemental input')
        .attr("value", "")
        .attr("data-id", "")
        .attr("data-value", "")
        .attr("data-link", "false")
        .attr("data-text", "All Specialties");

      $('.jsLocSupplemental .select-dropdown-text').html("All Specialties");
      $('.jsLocSupplemental .select-dropdown-options li').removeClass("selected");
      $('.jsLocSupplemental .select-dropdown-options li:first-of-type').addClass("selected");
    }
  });

  $('.jsLocSupplemental .select-dropdown-value').on('change', function () {
    supplementDropdownValue = $(this).val();
    $('#filterLocationTypes').change();
  })
});
;
$(document).ready(function () {
  $(document).on('click', '#jsTooltipTrigger', function (event) {
    event.stopPropagation();
    $('.jsTooltip.opened').removeClass('opened');
    $(this).find('.jsTooltip').addClass('opened');
  });

  $(document).on('click', '.jsTooltipClose', function (event) {
    event.stopPropagation();
    $(this).parent().removeClass('opened');
  });

  $(document).on("click touchend", function (event) {
    var tooltip = $('.jsTooltip');

    if (event != null && tooltip.length > 0 && tooltip[0].contains(event.target)) return;
    tooltip.removeClass('opened');
  });

});
;
$(document).ready(function () {
  $('.jsLocationsTabMobile').on('click', function () {
    $('input[name="tabs"]').not(':checked').prop("checked", true).attr("id");    
  });  
});
;
function rad(x) {
  return x * Math.PI / 180;
}

var methodist = methodist || {};

methodist.components = methodist.components || {};
methodist.components.locations = methodist.components.locations || {};
methodist.components.locations.map = methodist.components.locations.map || {
  geometry: {
    getDistance: function (p1, p2) {
      var R = 6378137; // Earth’s mean radius in meter
      var dLat = rad(p2.lat() - p1.lat());
      var dLong = rad(p2.lng() - p1.lng());
      var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
        Math.cos(rad(p1.lat())) * Math.cos(rad(p2.lat())) *
        Math.sin(dLong / 2) * Math.sin(dLong / 2);
      var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
      var d = R * c;
      return d; // returns the distance in meter
    }
  },
  setup: function (data, options) {
    sessionStorage.removeItem("hm_locations");

    var map, oms;
    var mapOptions = options.useMap ? {
      zoom: options.zoomLevel ? options.zoomLevel : 9,
      center: options.center,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      disableDefaultUI: false,
      controlSize: 18,
      styles: [
        {
          featureType: "poi",
          elementType: "labels",
          stylers: [{
            visibility: "off"
          }]
        }
      ]
    } : null;

    var listOptions = {
      mirroring: options.mirroring,
      loadAmount: options.loadAmount || 10,
      loadMoreStopAt: options.loadMoreStopAt || 0,
      searchedLocationType: options.searchedLocationType || "",
      searchedText: options.searchedText || "",
      searchedRadius: options.searchedRadius || "",
      searchedSupplement: options.searchedSupplement || "",
      useFilter: options.useFilter || false,
      filterItems: options.filterItems || document.querySelectorAll(
        ".centralizedLocationsFilter > .locations-filter-dropdown > ul.dropdown-menu > li > a"
      ),
      filterButton: options.filterButton || document.querySelector("#locations-filter-button")
    }

    var mapTab = document.querySelector("input#mapTab[type=radio]");
    var listTab = document.querySelector("input#listTab[type=radio]");
    var listResults = document.querySelector("#divFilteredResults");

    if (mapOptions) {

      google.maps.Map.prototype.initialized = false;
      google.maps.Map.prototype.reloaded = false;

      map = new google.maps.Map(
        document.getElementById("googleMap"),
        mapOptions
      );

      oms = new OverlappingMarkerSpiderfier(map, { keepSpiderfied: true });
      oms.addListener("format", function (marker, status) {
        var url = status === OverlappingMarkerSpiderfier.markerStatus.SPIDERFIED
          ? getMapIcon(4)
          : getMapIcon(0);

        marker.setIcon({
          url: url
        });
      });

      var color = "#707070";
      var mti = google.maps.MapTypeId;
      oms.legColors.usual[mti.HYBRID] = color;
      oms.legColors.usual[mti.SATELLITE] = color;
      oms.legColors.usual[mti.TERRAIN] = color;
      oms.legColors.usual[mti.ROADMAP] = color;
      oms.legColors.highlighted[mti.HYBRID] = color;
      oms.legColors.highlighted[mti.SATELLITE] = color;
      oms.legColors.highlighted[mti.TERRAIN] = color;
      oms.legColors.highlighted[mti.ROADMAP] = color;

      cluster = new MarkerClusterer(map, [], {
        maxZoom: options.maxZoomLevel,
        gridSize: 30,
        styles: [
          {
            url: "/medialibrary/images/cluster.png",
            width: 20,
            height: 28,
            textSize: 12,
            textColor: "#FFF",
            anchorText: [-3, 0],
            fontFamily: "Titillium Web"
          }
        ]
      });

      var infowindow = new google.maps.InfoWindow({
        content: "",
        maxWidth: 236,
      });

      google.maps.event.addListener(infowindow, "domready", function () {
        if (typeof Invoca !== "undefined") {
          var canRun = Invoca.Client &&
            typeof (Invoca.Client.checkConditionToRunInvoca) === "function" &&
            Invoca.Client.checkConditionToRunInvoca();
          if (canRun) {
            Invoca.PNAPI.run();
          }
        }
      });
    }

    var process = function (locations, setEventListeners, reload) {
      if (map && options.useMap === true) {
        map.reloaded = reload || false;
        oms.clearMarkers();
        cluster.clearMarkers();

        var bounds = new google.maps.LatLngBounds();
        var markers = locations.map(function (location) {

          var mapIcon = getMapIcon(0);
          var marker = new google.maps.Marker({
            position: new google.maps.LatLng(location.Latitude, location.Longitude),
            icon: mapIcon,
            clickable: true,
            zIndex: google.maps.Marker.MAX_ZINDEX + 1,
            title: location.ShortLocationName,
            hash: location.ID.Guid
          });

          var html = [];

          html.push("<p class='locationTitleSpan'>");
          if (location.WebPageUrl && location.ShouldDisplayAsLink) {
            html.push("<a href='");
            html.push(location.WebPageUrl);
            html.push("' target='");
            html.push(location.WebPageTarget);
            html.push("' class='locationTitle' data-analytics='location-map:" + (location.AnalyticsTag || "location-details") + "' data-target='location-name' data-source='map' data-title='" + location.Title + "' title='");
            html.push(location.Title);
            html.push("'>");
            html.push(location.ShortTitle);
            html.push("</a>");
          } else {
            html.push(location.ShortTitle);
          }
          html.push("</p>");

          html.push("<p class='locationSection'>");
          html.push(location.Address1);

          if (location.Address2) {
            html.push("<br/>");
            html.push(" ");
            html.push(location.Address2);
          }

          html.push("<br/>");

          html.push(location.City);
          html.push(", ");
          html.push(location.State);
          html.push(" ");
          html.push(location.ZIPCode);

          html.push("</p>");

          html.push("<p class='locationSection'>");
          html.push("<a href='");
          html.push(location.MapUrl);
          html.push("' target='_blank' data-analytics='location-map:" + (location.AnalyticsTag || "location-details") + "' data-target='location-directions' data-source='map' data-title='" + location.Title + "'>Get Directions</a>");
          html.push("</p>");

          if (options.mapViewHoursOfOperation && location.HoursOfOperation) {
            html.push("<p class='locationSection'>");
            html.push("<b>Hours:</b>");
            html.push(" ");
            html.push(location.HoursOfOperation);
            html.push("</p>");
          }

          if (location.PhoneNumber) {
            html.push("<p class='locationSection'>")
            html.push("<a href='tel://");
            html.push(location.PhoneNumber);
            html.push("' data-analytics='location-map:" + (location.AnalyticsTag || "location-details") + "' data-target='location-phone-call' data-source='map' data-title='" + location.Title + "'>");
            html.push(location.PhoneNumber);
            html.push("</a>");
            html.push("</p>");
          }

          if (location.FindADoctorUrl || location.RequestAppointmentUrl) {
            html.push("<p class='locationSection'>");
            html.push(createLinksHtml(location));
            html.push("</p>");
          }

          google.maps.event.addListener(marker, 'spider_click', function () {
            infowindow.setContent(html.join(""));
            infowindow.open(map, marker);
          });

          oms.addMarker(marker);
          cluster.addMarker(marker);

          bounds.extend(marker.position);

          return marker;
        });

        if (markers.length == 1) {
          map.setZoom(10);
          map.setCenter(markers[0].position);
        } else if (markers.length > 1) {
          var center = options.center;

          if (!options.zoomLevel && Object.keys(options.focus).length === 0) {
            map.fitBounds(bounds);
          } else {
            var mapBounds = map.getBounds();
            if (options.autoFitCenter) {
              map.fitBounds(bounds);
            } else if (mapBounds && mapBounds.contains(center)) {
              map.setCenter(center);
            }
          }
        }
      }

      /* --- Set Event Listeners --- */
      if (setEventListeners) {
        if (options.useFilter && options.filterButton) {
          options.filterButton.addEventListener("click", clearTooltips);
        }

        document.querySelector("div.jsLocationsTabMobile").addEventListener("click", function () {
          var view = getCurrentView();
          if (view) {
            if (view === "map") {
              switchLocationView("list");
            } else {
              switchLocationView("map");
            }
          }
        });

        mapTab?.addEventListener("click", function () {
          if (this.checked === true) {
            switchLocationView("map");
          }
        });

        listTab?.addEventListener("click", function () {
          if (this.checked === true) {
            switchLocationView("list");
          }
        });

        document.querySelector("#loadMoreLocations").addEventListener("click", function (event) {
          event.preventDefault();

          var items = getListItems();
          if (items.length > 0) {
            var itemsToDisplay = Array.prototype.slice.call(items).slice(
              0,
              listOptions.loadMoreStopAt + listOptions.loadAmount
            );

            itemsToDisplay.forEach(function (item) {
              if (item.offsetParent == null) {
                item.style.display = "";
              }
            });
          }

          updateLoadMore(true, items);
        });

        if (listOptions.mirroring && options.useMap === true) {
          google.maps.event.addListener(
            map,
            "bounds_changed",
            function () {
              if (!map.reloaded && map.initialized) {
                filterByViewport(markers);
              }
              map.reloaded = false;
            }
          );

          google.maps.event.addListener(
            map,
            "zoom_changed",
            function () {
              if (!map.reloaded && map.initialized) {
                filterByViewport(markers);
              }
              map.reloaded = false;
            }
          );
        }

        var initLocationsFilterDropdown = function (items) {
          Array.prototype.forEach.call(items, function (item) {
            item.addEventListener("click", function () {
              var currentType = this.innerText;
              document.querySelector(".centralizedLocationsFilter > .locations-filter-dropdown .button-text").innerText = currentType;
              var service = this.getAttribute('data-service-id');
              if (service) {
                filterByLocationType(service);
              } else {
                clearTypeFilter();
              }
            });
          });
        }

        initLocationsFilterDropdown(listOptions.filterItems);
      }
    }

    /* --- Misc Actions --- */
    var switchLocationView = function (view) {
      if (view) {
        var centralizedLocationsTab = document.querySelector("div.centralizedLocationsTabs[data-location-view]");
        centralizedLocationsTab.setAttribute("data-location-view", view === "map" ? "map" : "list");
      }

      if (view === "map") {
        if (isMapReloadPending()) {
          var locations = getFilteredLocations();
          if (locations) {
            process(locations, false, true);
          }
        }
      }
    }

    var updateLoadMore = function (increase, locationData) {
      if (increase) {
        listOptions.loadMoreStopAt += listOptions.loadAmount;
      }

      var locations = locationData || data || [];
      if (locations.length > listOptions.loadMoreStopAt) {
        document.querySelector("#loadMoreLocations").style.display = "block";
      } else {
        document.querySelector("#loadMoreLocations").style.display = "none";
      }      
    }

    var focus = function (config) {
      if (config.focus.zoom) {
        map.setZoom(parseInt(config.focus.zoom, 10));
      }

      var parseCoordinates = function (coordinates) {
        return coordinates.hasOwnProperty('lat') && coordinates.hasOwnProperty('lng');
      }

      if (config.focus.center) {
        if (parseCoordinates(config.focus.center)) {
          map.setCenter(config.focus.center);
        }
      }

      if (config.scroll && config.scroll === "QueryString") {
        $([document.documentElement, document.body]).animate({
          scrollTop: $(".container.loc-map").offset().top
        }, 750, "swing");
      }
    }

    /* --- Filter Actions --- */

    var isMapReloadPending = function () {
      var reload = mapTab.getAttribute('data-map-reload');

      if (reload !== null && reload !== undefined) {
        mapTab.removeAttribute("data-map-reload");
        return true;
      }

      return false;
    }

    var getFilteredLocations = function (type) {
      if (type !== "" && type !== undefined) {
        return filterLocations(type);
      } else {
        var locationsFromStorage = sessionStorage.getItem("hm_locations");
        if (locationsFromStorage) {
          locationsFromStorage = JSON.parse(locationsFromStorage);
          return locationsFromStorage;
        }

        return data;
      }
    }

    var filterLocations = function (type) {
      if (type !== "" && type !== undefined) {
        var filteredLocations = data.reduce(
          function (accumulator, location) {
            if (location.LocationTypes.indexOf(type) > -1) {
              accumulator.push(location);
            }
            return accumulator;
          },
          []
        );

        return filteredLocations;
      }

      return data;
    }

    var filterByLocationType = function (type) {
      resetLoadMoreStart();
      clearTooltips();
      listResults.innerHTML = "";

      var filteredLocations = getFilteredLocations(type);
      sessionStorage.setItem("hm_locations", JSON.stringify(filteredLocations));

      if (filteredLocations.length > 0) {
        clearErrorText();
      }

      var view = getCurrentView();
      if (view === "map") {
        process(filteredLocations, false, true);
      } else {
        mapTab.setAttribute("data-map-reload", "true");
      }

      createLocationsHtml(filteredLocations);
      updateLoadMore(true, filteredLocations);

      if (filteredLocations.length === 0) {
        setErrorText();
      }
    }

    var filterByViewport = function (markers) {
      resetLoadMoreStart();
      listResults.innerHTML = "";

      var locations = getFilteredLocations();
      var visibleLocations = getVisibleLocations(map, markers, locations);

      createLocationsHtml(visibleLocations);
      updateLoadMore(true, visibleLocations);

      if (visibleLocations.length === 0) {
        setErrorText(true, "No locations visible on the map. Please update your selection.");
      }
    }

    /* --- Create HTML Actions --- */
    var createLocationsHtml = function (l) {
      if (listResults) {
        l.forEach(function (location) {
          var child = createLocationDetailHtml(location);

          if (l.indexOf(location) >= listOptions.loadAmount) {
            child.style.display = "none";
          }

          listResults.appendChild(child);
        });
      }
    }

    var createLocationDetailHtml = function (location) {
      var template = document.getElementById("location-list-item");
      var item = document.createElement('div');
      var html = template.innerHTML;

      var hours = (location.HoursOfOperation || "").trim();
      var information = (location.Information || "").trim();

      html = html.replace(/\{0\}/g, location.WebPageUrl || "#");
      html = html.replace(/\{1\}/g, location.WebPageUrl && location.ShouldDisplayAsLink ? "" : "no-interactive");
      html = html.replace(/\{2\}/g, location.Image ? location.Image : "/medialibrary/images/HM_LocationsImageAvatar.jpg");
      html = html.replace(/\{3\}/g, location.Title);
      html = html.replace(/\{4\}/g, location.BuildingName ? "<strong>" + location.BuildingName + "</strong>" : "");
      html = html.replace(/\{5\}/g, createAddress(location));
      html = html.replace(/\{6\}/g, location.MapUrl);
      html = html.replace(/\{7\}/g, createPhoneDesktop(location.PhoneNumber));
      html = html.replace(/\{8\}/g, createPhoneMobile(location.PhoneNumber, location.Title, location.AnalyticsTag));
      html = html.replace(/\{9\}/g, hours || information ? createLocationDetails(location) : "");
      html = html.replace(/\{10\}/g, createLinksHtml(location, true));
      html = html.replace(/\{11\}/g, options.listViewHoursOfOperation && hours ? createHoursOfOperation(location) : "");
      html = html.replace(/\{12\}/g, location.WebPageTarget);
      html = html.replace(/\{13\}/g, location.AnalyticsTag || "location-details");

      item.innerHTML = html;
      return item.firstElementChild;
    }

    var createAddress = function (location) {
      var html = [location.Address1];

      if (location.Address2) {
        html.push("</br>");
        html.push(location.Address2);
      }

      html.push("</br>");
      html.push(location.City);
      html.push(", ");
      html.push(location.State);
      html.push(" ");
      html.push(location.ZIPCode);

      return html.join("");
    }

    var createHoursOfOperation = function (location) {
      var html = ["<div>"];

      html.push("<b>Hours:</b>");
      html.push(" ");
      html.push(location.HoursOfOperation);

      html.push("</div>");

      return html.join("");
    }

    var createLocationDetails = function (location) {
      var html = ["<span id='jsTooltipTrigger' class='locationDetailsTrigger' data-analytics='location-map:" + (location.AnalyticsTag || "location-details") + "' data-target='location-details' data-source='list' data-title='" + location.Title + "'>View Location Details"];

      html.push("<div class='centralizedLocationsTooltip jsTooltip'>");

      if (location.HoursOfOperation) {
        html.push("<p>");
        html.push(location.HoursOfOperation);
        html.push("</p>");
      }

      if (location.Information) {
        html.push("<p>");
        html.push(location.Information);
        html.push("</p>");
      }

      html.push("<span class='centralizedLocationsTooltipClose jsTooltipClose'>&times;</span>");
      html.push("</div>");
      html.push("</span>");

      return html.join("");
    }

    var createLinksHtml = function (location, useButtons) {
      var html = [];

      if (location.FindADoctorUrl) {
        html.push("<a href='");
        html.push(location.FindADoctorUrl);

        if (useButtons) {
          html.push("' class='btn blue-button locations-button' alt='");
          html.push(location.FindADoctorText);
        }

        html.push("' target='");
        html.push(location.FindADoctorTarget);
        if (useButtons) {
          html.push("' data-analytics='location-map:" + (location.AnalyticsTag || "location-details") + "' data-target='" + location.FindADoctorText + "' data-source='map' data-title='" + location.Title + "'>");
        } else {
          html.push("' data-analytics='location-map:" + (location.AnalyticsTag || "location-details") + "' data-target='" + location.FindADoctorText + "' data-source='list' data-title='" + location.Title + "'>");
        }
        html.push(location.FindADoctorText);
        html.push("</a>");

        if (!useButtons) {
          html.push("<br />");
        }
      }

      if (location.RequestAppointmentUrl) {
        html.push("<a href='");
        html.push(location.RequestAppointmentUrl);

        if (useButtons) {
          html.push("' class='btn light-blue-button locations-button' alt='");
          html.push(location.RequestAppointmentText);
        }

        html.push("' target='");
        html.push(location.RequestAppointmentTarget);
        if (useButtons) {
          html.push("' data-analytics='location-map:" + (location.AnalyticsTag || "location-details") + "' data-target='" + location.RequestAppointmentText + "' data-source='map' data-title='" + location.Title + "'>");
        } else {
          html.push("' data-analytics='location-map:" + (location.AnalyticsTag || "location-details") + "' data-target='" + location.RequestAppointmentText + "' data-source='list' data-title='" + location.Title + "'>");
        }
        html.push(location.RequestAppointmentText);
        html.push("</a>");

        if (!useButtons) {
          html.push("<br />");
        }
      }

      return html.join("");
    }

    var createPhoneDesktop = function (phone) {
      if (!phone) return "";

      return "<span class='btn outerLinkBtn centralizedLocationsListPhone hidden-xs'>" + phone + "</span>";
    }

    var createPhoneMobile = function (phone, title, analytics) {
      if (!phone) return "";

      return "<a href='tel://" + phone + "' data-analytics='location-map:" + (analytics || "location-details") + "' data-target='location-phone-call' data-source='list' data-title='" + title + "' class='btn button-skeleton locations-button centralizedLocationsListPhone visible-xs'>Call</a>";
    }

    /* --- Get Actions --- */
    var getListItems = function () {
      if (listResults) {
        return listResults.children || [];
      }
    }

    var getMapIcon = function (type) {
      var pinColor = "";

      switch (type) {
        case 0:
          pinColor = "/medialibrary/images/singlepindarkblue.png";
          break;

        case 1:
          pinColor = "/medialibrary/images/singlepingreen.png";
          break;

        case 2:
          pinColor = "/medialibrary/images/singlepinred.png";
          break;

        case 3:
          pinColor = "/medialibrary/images/singlepinorange.png";
          break;

        case 4:
          pinColor = "/medialibrary/images/singlepinblue.png";
          break;

        case 5:
          pinColor = "/medialibrary/images/singlepinblue.png";
          break;

        case 99:
          pinColor = "/medialibrary/images/doublepin.png";
          break;
      }

      return pinColor;
    }

    var getCurrentView = function () {
      var centralizedLocationsTab = document.querySelector("div.centralizedLocationsTabs[data-location-view]");
      if (centralizedLocationsTab) {
        var currentView = centralizedLocationsTab.getAttribute("data-location-view");
        if (currentView === "map") {
          return currentView;
        } else {
          return "list";
        }
      }

      return false;
    }

    /* --- Set Actions ---*/
    var setErrorText = function (skipMap, message) {
      message = message || "No locations were found using this criteria. Please choose a different filter option.";

      if (!skipMap) {
        var error = document.querySelector(".centralizedLocationsTabs .centralizedLocationsError");
        if (error) {
          error.innerHTML = "<p>" + message + "</p>";
        }
      }

      var html = document.querySelector("#location-list-item-error").innerHTML;
      html = html.replace(/\{0\}/g, "/medialibrary/images/HM_LocationsImageAvatar.jpg");
      html = html.replace(/\{1\}/g, message);

      if (listResults) {
        listResults.innerHTML = "";
        listResults.innerHTML += html;
      }
    }

    /* --- Clear Actions --- */
    var clearTypeFilter = function () {
      sessionStorage.removeItem("hm_locations");
      document.querySelector("#divFilteredResults").innerHTML = "";
      resetLoadMoreStart();
      clearErrorText();

      var view = getCurrentView();
      if (view === "list") {
        mapTab.setAttribute("data-map-reload", "true");
      }

      createLocationsHtml(data);
      process(data, false, true);
      updateLoadMore(true);

      sessionStorage.setItem("hm_locations", JSON.stringify(data));
    }

    var clearTooltips = function () {
      var tooltips = document.querySelectorAll(".centralizedLocationsTooltip.jsTooltip.opened");
      Array.prototype.forEach.call(tooltips, function (tooltip) {
        tooltip.classList.remove("opened");
      });
    }

    var clearErrorText = function () {
      var error = document.querySelector(".centralizedLocationsTabs .centralizedLocationsError");
      if (error) {
        error.innerHTML = "";
      }
    }

    var resetLoadMoreStart = function () {
      listOptions.loadMoreStopAt = 0;
    }

    process(data, true);
    createLocationsHtml(data);
    updateLoadMore(true);

    setTimeout(function () {
      if (map && options.useMap === true) map.initialized = true;
      if (Object.keys(options.focus).length > 0) {
        focus({ focus: options.focus, scroll: options.scroll });
      }

      if (options.scroll === "Always" || [true, "true", 1, "1"].indexOf(options.scroll) > -1) {
        $([document.documentElement, document.body]).animate({
          scrollTop: $(".container.loc-map").offset().top
        }, 750, "swing");
      }
    }, 1500);

    $(document).on("click", "#" + options.id + " [data-analytics^='location-map:']", function (ev) {
      if (ev.target == null) return;

      var target = ev.target.getAttribute("data-analytics");
      if (target == null || target.trim().length === 0) return;

      var trigger = target.substring("location-map:".length);
      var view = ev.target.getAttribute("data-source");
      var element = ev.target.getAttribute("data-target");
      var location = ev.target.getAttribute("data-title");

      methodist.analytics.pushEvent(
        "location_cta_clicked",
        {
          component: Object.assign(
            {},
            options.analytics.component,
            {
              sc_data_analytics_name: trigger,
              sc_component_cta_element: element,
              sc_component_view_type: view,
              sc_location_name: location
            }
          )          
        }
      );
    });
  }
}
;
function getVisibleMarkers(map, marks) {
  var bounds = map.getBounds();

  var visibleMarkers = marks.reduce(
    function (accumulator, marker) {
      if (bounds.contains(marker.getPosition())) {
        accumulator.push(marker.hash);
      }
      return accumulator;
    },
    []
  );

  return visibleMarkers;
}

function getVisibleLocations(map, marks, locations) {
  var visibleMarkers = getVisibleMarkers(map, marks);

  var inView = locations.filter(function (l) {
    return visibleMarkers.indexOf(l.ID.Guid) > -1;
  });

  return inView;
}
;
