jQuery(document).ready(function($) {
  var scrollup = $('.scroll-top');

  // Hide the scroll-to-top button initially
  scrollup.hide();

  /*------------------------------------------------
            Scroll Top
  ------------------------------------------------*/
  scrollup.click(function () {
    $('html, body').animate({
      scrollTop: '0px'
    }, 800);
    return false;
  });

  $(window).scroll(function () {
    var scroll = $(window).scrollTop();
    if (scroll >= 200) {
      scrollup.fadeIn();
    } else {
      scrollup.fadeOut();
    }
  });
});

document.addEventListener("DOMContentLoaded", function () {
  const container = document.getElementById("screenshotContainer");
  const image = document.getElementById("scrollImage");
  let scrollInterval;
  let currentTop = 0;
  const speed = 1; // pixels per step
  const delay = 10; // milliseconds per step

  container.addEventListener("mouseenter", function () {
      const containerHeight = container.offsetHeight;
      const imageHeight = image.offsetHeight;
      const maxScroll = imageHeight - containerHeight;

      scrollInterval = setInterval(() => {
          if (currentTop > -maxScroll) {
              currentTop -= speed;
              image.style.top = currentTop + "px";
          } else {
              clearInterval(scrollInterval);
          }
      }, delay);
  });

  container.addEventListener("mouseleave", function () {
      clearInterval(scrollInterval);
      currentTop = 0;
      image.style.top = "0px";
  });
});

// Slider Js

jQuery(document).ready(function(){
  var owl = jQuery('.slider-upper .owl-carousel');
    owl.owlCarousel({
    margin: 20,
    nav: true,
    autoplay: true,
    lazyLoad: true,
    autoplayTimeout: 3000,
    loop: true,
    dots: false,
    navText: ['<span class="dashicons dashicons-arrow-left-alt"></span>','<span class="dashicons dashicons-arrow-right-alt"></span>'],
    responsive: {
      0: {
        items: 1,
        nav: false
      },
      600: {
        items: 1,
        nav: false
      },
      1000: {
        items: 1
      }
    },
    autoplayHoverPause: true,
    mouseDrag: true
  });

  var owl = jQuery('.category-section .owl-carousel');
    owl.owlCarousel({
    margin: 20,
    nav: true,
    autoplay: true,
    lazyLoad: true,
    autoplayTimeout: 3000,
    loop: true,
    dots: true,
    navText: ['<span class="dashicons dashicons-arrow-left-alt"></span>','<span class="dashicons dashicons-arrow-right-alt"></span>'],
    responsive: {
      0: {
        items: 1,
        nav: false
      },
      600: {
        items: 2,
        nav: false
      },
      1000: {
        items: 2
      },
      1200: {
        items: 4
      }
    },
    autoplayHoverPause: true,
    mouseDrag: true
  });
});

document.addEventListener("DOMContentLoaded", function () {
  // Run only if Gutentor is present
  if (document.querySelector(".gtf-item")) {
    document.querySelectorAll(".gtf-item").forEach(function (item) {
      let title = item.querySelector(".g-d-title");
      let count = item.querySelector(".g-d-count");

      if (title && count) {
        // Create wrapper div
        let newDiv = document.createElement("div");
        newDiv.classList.add("custom-title-count");

        // Move original title and count inside new div
        newDiv.appendChild(title);
        newDiv.appendChild(count);

        // Insert new div where title was
        item.insertBefore(newDiv, item.querySelector(".g-d-title, .g-d-count"));
      }
    });
  }
});

