/** ============================================================
 *  JS File for Kipya Template
 *===============================================================*/
$(document).ready(function() {
    $('.menu-item').hover(
        function() {
            $(this).children('.sub-menu').stop(true, true).slideDown(200); // Adjust the speed as needed
        },
        function() {
            $(this).children('.sub-menu').stop(true, true).slideUp(200);
        }
    );
});

jQuery(document).ready(function ($) {
    console.log("GLightbox script loaded!"); // Debugging log

    $('.home-gallery-item .wp-block-image').each(function () {
        var img = $(this).find('img');

        if (img.length) {
            var src = img.attr('src');
            var parentLink = img.parent('a');

            if (!parentLink.length) {
                console.log("Wrapping image:", src);
                img.wrap('<a href="' + src + '" class="gallery-lightbox" data-glightbox="gallery"></a>');
            }
        }
    });

    // Initialize GLightbox
    const lightbox = GLightbox({
        selector: '.gallery-lightbox',
        touchNavigation: true,
        loop: true,
        closeButton: true,
        autoplayVideos: false
    });

    console.log("GLightbox initialized!");
});


/** ============================================================================
 * HEADER SCROLL
*=============================================================================*/
document.addEventListener("DOMContentLoaded", function() {
    var header = document.querySelector('.menu-section');
    var header2 = document.querySelector('.menu-section2');
    
    if (header && header2) { // Check if both headers are present
        window.addEventListener('scroll', function() {
            if (window.scrollY > 100) {
                header.classList.add('sticky-header');
                header2.classList.add('sticky-header');
            } else {
                header.classList.remove('sticky-header');
                header2.classList.remove('sticky-header');
            }
        });
    } else if (header) { // Only header1 is present
        window.addEventListener('scroll', function() {
            if (window.scrollY > 100) {
                header.classList.add('sticky-header');
            } else {
                header.classList.remove('sticky-header');
            }
        });
    } else if (header2) { // Only header2 is present
        window.addEventListener('scroll', function() {
            if (window.scrollY > 100) {
                header2.classList.add('sticky-header');
            } else {
                header2.classList.remove('sticky-header');
            }
        });
    }
});


/**====================================================
   * Slides - Animation JS
   *====================================================**/
function thmSwiperInit() {
    // swiper slider
    if ($(".thm-swiper__slider").length) {
      $(".thm-swiper__slider").each(function () {
        let elm = $(this);
        let options = elm.data('swiper-options');
        let thmSwiperSlider = new Swiper(elm, options);
      });
    }
  }
  if ($(".banner-bg-slide").length) {
    $(".banner-bg-slide").each(function () {
      var Self = $(this);
      var bgSlideOptions = Self.data("options");
      var bannerTwoSlides = Self.vegas(bgSlideOptions);
    });
  }
  if ($(".wow").length) {
    var wow = new WOW({
      boxClass: "wow", // animated element css class (default is wow)
      animateClass: "animated", // animation css class (default is animated)
      mobile: true, // trigger animations on mobile devices (default is true)
      live: true // act on asynchronously loaded content (default is true)
    });
    wow.init();
  }
    // window load event
    $(window).on("load", function () {

      thmSwiperInit();
      //thmOwlInit();
      //handlePreloader();
      //languageSwitcher();
      //projectMasonaryLayout();
  
  
      //Jquery Spinner / Quantity Spinner
      if ($('.quantity-spinner').length) {
        $("input.quantity-spinner").TouchSpin({
          verticalbuttons: true
        });
      }
  
    });

/**====================================
* AOS
=====================================**/
     document.addEventListener('DOMContentLoaded', function () {
    // Initialize AOS for each column
    if (typeof AOS !== 'undefined') {
        AOS.init({
            duration: 1000,
            easing: 'ease-in-out',
            once: true,
            mirror: false,
        });
    }
});
/** ===============================================
 * Back to Top
 *=================================================*/
function select(selector) {
    return document.querySelector(selector);
}

// Check if the back-to-top element exists
var backtotop = select('.back-to-top');
if (backtotop) {
    const toggleBacktotop = () => {
        if (window.scrollY > 400) { // Change threshold to 200
            backtotop.classList.add('active');
        } else {
            backtotop.classList.remove('active');
        }
    };

    window.addEventListener('load', toggleBacktotop);
    window.addEventListener('scroll', toggleBacktotop);
    
    // Scroll to top on click
    backtotop.addEventListener('click', () => {
        window.scrollTo({
            top: 0,
            behavior: 'smooth' // Smooth scroll to top
        });
    });
}
 /**====================================
     * HIDE OVERFLOW
=====================================**/
     
(function ($, root, undefined) {
	
	$(function () {
		
		'use strict';
		
		// DOM ready, take it away
		$("html").attr("style", "overflow-x:hidden;");
		
	});
	
})(jQuery, this);
