jQuery(function($){

// counter //

$(document).ready(function () {
    $('.counter-value').each(function () {
        $(this).prop('Counter', 0).animate({
            Counter: $(this).text()
        }, {
            duration: 3500,
            easing: 'swing',
            step: function (now) {
                $(this).text(Math.ceil(now));
            }
        });
    });
});



// // bottom to top button

$(document).ready(function () {
    $('.top').hide(0)

    $(window).scroll(function () {
        if ($(this).scrollTop() > 100) {
            $('.top').fadeIn(200);
        } else {
            $('.top').fadeOut(300);
        }
    });
    $('.top').click(function () {
        event.preventDefault();

        $('html , body').animate({ scrollTop: 0 }, 500);
    });
});

function topFunction() {
    document.body.scrollTop = 0;
    document.documentElement.scrollTop = 0;
}


// masonsary

function masonsary() {
    // blog masonry
    var $grid = $(".grid").masonry({
        // options
        itemSelector: ".grid-item",
        columnWidth: ".grid-item",
        // percentPosition: true,
        gutter: 0,
        fitWidth: false
    });

    var gridItems = $(".grid-item");
    if (gridItems.length > 0) {
        $grid.imagesLoaded().progress(function () {
            $grid.masonry("layout");
        });
    } else {
    }

}
masonsary();


// my account form //

function showHide() {
    var password = document.getElementById("password");
    if (password.type === "password") {
        password.type = "text";
    } else {
        password.type = "password";
    }
}


// menu bar //

$(".dropdown-toggle").on("click", function (e) {
    // Check if the screen width is less than or equal to 991px
    if (window.innerWidth <= 991) {
        e.preventDefault();
        $(this).parent().toggleClass("current");
        $(this).next().slideToggle();
    }
});


function menuSticky() {
    if ($(".is-sticky-on").length > 0) {
        $(window).on('scroll', function () {
            if ($(window).scrollTop() >= 250) {
                $('.is-sticky-on').addClass('is-sticky-menu');
            }
            else {
                $('.is-sticky-on').removeClass('is-sticky-menu');
            }
        });
    }
}
menuSticky();

// JavaScript
function playVideo() {
    // JavaScript
    class VideoModalManager {
        constructor() {
            this.init();
        }
        init() {
            $('.video-btn').click(function () {
                const $videoSrc = $(this).data("src");
                $('.modal').data("videoSrc", $videoSrc);
            });
            $('.modal').on('shown.bs.modal', function (e) {
                const $videoSrc = $(this).data("videoSrc");
                console.log("Video Source in modal:", $videoSrc); // Debugging
                $(this).find(".modal-body .video iframe").attr('src', $videoSrc + "?autoplay=1&modestbranding=1&showinfo=0");
            });
            $('.modal').on('hide.bs.modal', function (e) {
                $(this).find(".modal-body .video iframe").attr('src', '');
            });
        }
    }
    // Initialize the VideoModalManager
    const videoModalManager = new VideoModalManager();
}

playVideo();
});