$("#site-navigation").on("shown.bs.modal", function () {
  $("body").addClass("modal-open-menu-mobile");
});
$("#site-navigation").on("hide.bs.modal", function () {
  $("body").removeClass("modal-open-menu-mobile");
});
$("#site-search").on("shown.bs.modal", function () {
  $("#search").focus();
  $("body").addClass("search-modal-open");
});
$("#site-search").on("hide.bs.modal", function () {
  $("body").removeClass("search-modal-open");
});
$("#profile-modal").on("show.bs.modal", function () {
  $("body").addClass("profile-modal-open");
});
$("#profile-modal").on("hide.bs.modal", function () {
  $("body").removeClass("profile-modal-open");
});
$("#video-modal").on("show.bs.modal", function () {
  $("body").addClass("video-modal-open");
});
$("#video-modal").on("hide.bs.modal", function () {
  $("body").removeClass("video-modal-open");
});
$(".menu-close").click(function () {
  $(".modal").modal("hide");
});
$(".menu-toggle").click(function () {
  $("#site-search").modal("hide");
  $("body").addClass("modal-open");
});

$(".dropdown-toggle").on("shown.bs.dropdown", function () {
  $("#site-search").modal("hide");
  $("body").removeClass("search-modal-open");
});

jQuery(document).ready(function ($) {
  var alterClass = function () {
    var ww = document.body.clientWidth;
    if (ww >= 1200) {
      $(".modal").modal("hide");
    }
  };
  $(window).resize(function () {
    alterClass();
  });
  //Fire it when the page first loads:
  alterClass();
});

// Sticky Header
$(window).scroll(function () {
  var scroll = $(window).scrollTop();
  if (scroll >= 145) {
    $("body").addClass("sticky-show");
  } else {
    $("body").removeClass("sticky-show");
  }
});

jQuery(document).ready(function ($) {
  var alterClass = function () {
    $("body").css({ "padding-top": $("header").outerHeight() });

    $(".alert").on("closed.bs.alert", function () {
      $("body").removeClass("alert-visible");
      $("#site-search .modal-dialog").css({ top: "" });
      $("body").css({ "padding-top": $("header").outerHeight() });
      if ($(".sticky-show").length > 0) {
        $("body").css({ "padding-top": $("header").outerHeight() + 39 });
      }
    });
    if ($(".alert").length > 0) {
      $("body").addClass("alert-visible");
      $("#site-search .modal-dialog").css({ top: $(".alert").outerHeight() });
    }
  };
  $(window).resize(function () {
    alterClass();
  });
  //Fire it when the page first loads:
  alterClass();
});

jQuery(document).ready(function ($) {
  var alterClass = function () {
    var ww = document.body.clientWidth;
    if (ww <= 992) {
      $(".alert").on("closed.bs.alert", function () {
        if ($(".sticky-show").length > 0) {
          $("body").css({ "padding-top": $("header").outerHeight() + 0 });
        }
      });
    }
  };
  $(window).resize(function () {
    alterClass();
  });
  //Fire it when the page first loads:
  alterClass();
});

$(".aux a").focus(function () {
  $(".top-row").addClass("focus-visible");
});
$(".aux a").focusout(function () {
  $(".top-row").removeClass("focus-visible");
});

$(document).ready(function () {
  // Select all links with hashes
  $('a[href*="#"]')
    // Remove links that don't actually link to anything
    .not('[href="#"]')
    .not('[href="#0"]')
    .not("[data-toggle]")
    .click(function (event) {
      // On-page links
      if (
        location.pathname.replace(/^\//, "") ===
          this.pathname.replace(/^\//, "") &&
        location.hostname === this.hostname
      ) {
        // Figure out element to scroll to
        var target = $(this.hash);
        target = target.length
          ? target
          : $("[name=" + this.hash.slice(1) + "]");
        // Does a scroll target exist?
        if (target.length) {
          // Only prevent default if animation is actually gonna happen
          event.preventDefault();
          $("html, body").animate(
            {
              scrollTop: target.offset().top,
            },
            1000,
            function () {
              // Callback after animation
              // Must change focus!
              var $target = $(target);
              $target.focus();
              if ($target.is(":focus")) {
                // Checking if the target was focused
                return false;
              } else {
                $target.attr("tabindex", "-1"); // Adding tabindex for elements not focusable
                $target.focus(); // Set focus again
              }
            }
          );
        }
      }
    });
});

if (document.querySelector(".text-image-feature.slider") !== null) {
  $(document).ready(function () {
    $(".text-image-feature.slider").slick({
      dots: false,
      infinite: true,
      slidesToShow: 1,
      slidesToScroll: 1,
      accessibility: true,
      autoplay: false,
      focusOnSelect: true,
      pauseOnHover: false,
      speed: 900,
      autoplaySpeed: 10000,
      appendArrows: ".text-image-feature-button-container",
    });
  });
}

$(document).ready(function () {
  var playing = true;
  $(".play-pause").click(function () {
    if (playing == false) {
      document.getElementById("myVideo").play();
      playing = true;
      $(this).html("<span class='fi fi-ss-pause'></span>");
    } else {
      document.getElementById("myVideo").pause();
      playing = false;
      $(this).html("<span class='fi fi-ss-play'></span>");
    }
  });
});
// video playback script
$(document).ready(function () {
  // Gets the video src from the data-src on each button
  var $videoSrc;
  $(".load-video").click(function () {
    $videoSrc = $(this).data("src");
  });
  $(".load-video").keyup(function (event) {
    if (event.which === 13 || event.which === 32) {
      event.currentTarget.click();
    }
  });
  console.log($videoSrc);
  // when the modal is opened autoplay it
  $("#video-modal").on("shown.bs.modal", function (e) {
    // set the video src to autoplay and not to show related video.
    $("#video").attr(
      "src",
      $videoSrc + "?autoplay=1&amp;modestbranding=1&amp;showinfo=0"
    );
  });
  // stop playing the youtube video when I close the modal
  $("#video-modal").on("hide.bs.modal", function (e) {
    // a poor man's stop video
    $("#video").attr("src", $videoSrc);
  });
  // document ready
});

function getAccordion(element_id, screen) {
  $(window).resize(function () {
    if (/Mobi|Android/i.test(navigator.userAgent)) {
    } else {
      location.reload();
    }
  });

  if ($(window).width() < screen) {
    var concat = "";
    obj_tabs = $(element_id + " button").toArray();
    obj_cont = $(".tab-content .tab-pane").toArray();
    jQuery.each(obj_tabs, function (n, val) {
      concat += '<div class="accordion-item">';
      concat += '<h2 class="accordion-header" id="heading' + n + '">';
      concat +=
        '<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapse' +
        n +
        '" aria-expanded="false" aria-controls="collapse' +
        n +
        '">' +
        val.innerText +
        "</button>";
      concat += "</h2>";
      concat +=
        '<div id="collapse' +
        n +
        '" class="collapse" data-bs-parent="#accordion-tabs" aria-labelledby="heading' +
        n +
        '">';
      concat +=
        '<div class="accordion-body">' + obj_cont[n].innerHTML + "</div>";
      concat += "</div>";
      concat += "</div>";
    });
    $(".accordion.tabs-mobile").html(concat);
    $(".accordion.tabs-mobile").find(".panel-collapse:first").addClass("in");
    $(".accordion.tabs-mobile")
      .find(".panel-title a:first")
      .attr("aria-expanded", "true");
    $(element_id).remove();
    $(".tab-content").remove();

    $(".collapse").on("shown.bs.collapse", function () {
      var $accordionitem = $(this).closest(".accordion-item");

      $("html,body").animate(
        {
          scrollTop: $accordionitem.offset().top - $("header").outerHeight(),
        },
        0
      );
    });
  }
}

$(".text-image-feature .btn").hover(function () {
  $(".text-image-feature .image-wrapper").addClass("clear-background");
});
$(".text-image-feature .btn").mouseout(function () {
  $(".text-image-feature .image-wrapper").removeClass("clear-background");
});

$(".accordion .collapse").on("shown.bs.collapse", function () {
  var $accordionitem = $(this).closest(".accordion-item");

  $("html,body").animate(
    {
      scrollTop: $accordionitem.offset().top - $("header").outerHeight(),
    },
    0
  );
});

jQuery(document).ready(function ($) {
  var alterClass = function () {
    var ww = document.body.clientWidth;
    if (ww >= 992) {
      $(".image-menu .image-menu-item").hover(function () {
        var linkIndex = $(this).attr("data-img");
        $(".image-menu .image-wrapper img").attr("src", linkIndex + ".jpg");
      });
      $(".image-menu .image-menu-item").focusin(function () {
        var linkIndex = $(this).attr("data-img");
        $(".image-menu .image-wrapper img").attr("src", linkIndex + ".jpg");
      });
    }
  };
  $(window).resize(function () {
    alterClass();
  });
  //Fire it when the page first loads:
  alterClass();
});
