(function ($) {
  if ($("#blockpage-cursor").length) {
    $("#blockpage-cursor").addClass("blockpage-cursor");
    const links = Array.from(document.querySelectorAll("a"));
    const cursor = document.querySelector(".blockpage-cursor");
    const setCursorLocation = (e) => {
      let cursorLocation = `top: ${e.pageY - 37}px; left: ${e.pageX - 12}px;`;
      cursor.setAttribute("style", cursorLocation);
    };

    document.addEventListener("mousemove", setCursorLocation);
    links.forEach((item) => {
      item.addEventListener("mouseover", () => {
        cursor.classList.add("focus");
      });
      item.addEventListener("mouseleave", () => {
        cursor.classList.remove("focus");
      });
    });
  }

  jQuery(window).scroll(function () {
    if (jQuery(this).scrollTop() > 100) {
      jQuery(".blockpage-scrolltop-button a").fadeIn();
    } else {
      jQuery(".blockpage-scrolltop-button a").fadeOut();
    }
  });
  jQuery(".blockpage-scrolltop-button a").click(function () {
    jQuery("html, body").animate({ scrollTop: 0 }, 600);
    return false;
  });

  jQuery(window).scroll(function () {
    if (jQuery(this).scrollTop() >= 50) {
      jQuery(".blockpage-sticky-header").addClass("stikcy-enabled");
    } else {
      jQuery(".blockpage-sticky-header").removeClass("stikcy-enabled");
    }
  });
})(jQuery);
