

$(function(){
    var offset = 150,
        offset_shrink = 300,
        //browser window scroll (in pixels) after which the "back to top" link opacity is reduced
        offset_opacity = 1200,
        //duration of the top scrolling animation (in ms)
        scroll_top_duration = 500,
        //grab the "back to top" link
        $back_to_top = $('.cd-top');

    //hide or show the "back to top" link
    $(window).scroll(function () {
        $(this).scrollTop() > offset ?
            ($back_to_top.addClass('cd-is-visible'), $('.header').addClass('sticky-header')) :
            ($back_to_top.removeClass('cd-is-visible cd-fade-out'), $('.header').removeClass('sticky-header'));
        $(this).scrollTop() > offset_shrink ?
            $('.header').addClass('sticky-header-shrink') :
            $('.header').removeClass('sticky-header-shrink');
        if ($(this).scrollTop() > offset_opacity) {
            $back_to_top.addClass('cd-fade-out');
        }
    });
    //smooth scroll to top aa
    $back_to_top.on('click', function (event) {
        event.preventDefault();
        $('body,html').animate({
                scrollTop: 0,
            }, scroll_top_duration
        );
    });
})
// Add a scroll event listener to check the scroll position
window.addEventListener('scroll', function () {
    var scrollButton = document.querySelector('.scroll-to-top');
    var scrollHeight = 700; // Set the scroll height when the button should appear

    if (window.scrollY >= scrollHeight) {
        // If the scroll position is greater than or equal to the set height, show the button
        scrollButton.style.display = 'block';
    } else {
        // Otherwise, hide the button
        scrollButton.style.display = 'none';
    }
});

// Add a click event listener to scroll to the top when the button is clicked
document.querySelector('.scroll-to-top').addEventListener('click', function (e) {
    e.preventDefault();
    window.scrollTo({
        top: 0,
        behavior: 'smooth'
    });
});








$(function(){
    const searchWrap = $('.header-menu');
    $('.search-icon .trigger-click').click(function () {
        searchWrap.toggleClass('search-open');
    });
    $('.search-icon').click(function (event) {
        let e=event||window.event;
        if (e.cancelBubble) {
            e.cancelBubble=true;
        } else {
            e.stopPropagation();
        }
    });
    $(document).click(function () {
        if (searchWrap.hasClass('search-open')){
            $(this).removeClass('search-open');
        }
    })
})


$(function(){
    $('.mobile-dropdown-menu .menu-root').treemenu({
        'delay': 300,
    });
    const menuWrap =  $('.mobile-menu');
    const menuBtn = $('.mobile-menu .mobile-menu-trigger');
    menuBtn.click(function () {
        menuWrap.toggleClass('mobile-menu-open');
    });
    menuWrap.click(function (event) {
        let e=event||window.event;
        if (e.cancelBubble) {
            e.cancelBubble=true;
        } else {
            e.stopPropagation();
        }
    });
    $(document).click(function (e) {
        menuWrap.removeClass('mobile-menu-open');
    })
})








$(function () {
    $('.card-columns').isotope({
        itemSelector: '.card-grid',
        percentPosition: true,
        masonry: {
            columnWidth: '.card-grid-sizer'
        }
    })
});





$(function () {
    const $filterGrid = $('.block-gallery-filter .filter-contents').imagesLoaded(function () {
        $filterGrid.isotope({ filter: '*' })
        $('.block-gallery-filter .nav-filter').on( 'click', 'button', function() {
            let filterValue = $( this ).attr('data-filter');
            filterValue = filterValue === '*' ? '*' : '.'+filterValue
            $filterGrid.isotope({ filter: filterValue });
        });
        $('.block-gallery-filter .nav-filter').each(function (index, buttonGroup) {
            const $buttonGroup = $(buttonGroup);
            $buttonGroup.on( 'click', 'button', function() {
                $buttonGroup.find('.active').removeClass('active');
                $( this ).addClass('active');
            });
        })
    })
})





const swiperTestimonials = new Swiper(".block-testimonials .swiper-testimonials", {
    slidesPerView: 1,
    spaceBetween: 15,
    loop: true,
    pagination: {
        el: ".swiper-pagination",
        dynamicBullets: true,
        clickable: true,
    },
    breakpoints: {
        640: {
            slidesPerView: 1,
            spaceBetween: 30,
        },
        768: {
            slidesPerView: 2,
            spaceBetween: 15,
        },
        1024: {
            slidesPerView: 2,
            spaceBetween: 15,
        }
    },
});






















