(function ($) {
    "use strict";

    // Spinner
    setTimeout(function () {
        if ($('#spinner').length) $('#spinner').removeClass('show');
    }, 1);

    // WOW.js
    new WOW().init();

    // Navbar scroll effect
    $(window).scroll(function () {
        if ($(this).scrollTop() > 50) {
            $('.sgla-navbar').addClass('scrolled shadow');
        } else {
            $('.sgla-navbar').removeClass('scrolled shadow');
        }
    });

    // Dropdown hover on desktop
    var $dropdown = $(".dropdown");
    $(window).on("load resize", function () {
        if (window.matchMedia("(min-width: 992px)").matches) {
            $dropdown.hover(
                function () { $(this).addClass("show").find(".dropdown-toggle").attr("aria-expanded","true"); $(this).find(".dropdown-menu").addClass("show"); },
                function () { $(this).removeClass("show").find(".dropdown-toggle").attr("aria-expanded","false"); $(this).find(".dropdown-menu").removeClass("show"); }
            );
        } else {
            $dropdown.off("mouseenter mouseleave");
        }
    });

    // Counter Up
    $('[data-toggle="counter-up"]').counterUp({ delay: 10, time: 2000 });

    // Back to Top
    $(window).scroll(function () {
        if ($(this).scrollTop() > 120) {
            $('.back-to-top').fadeIn('slow').css('display','flex');
        } else {
            $('.back-to-top').fadeOut('slow');
        }
    });
    $('.back-to-top').click(function () {
        $('html, body').animate({ scrollTop: 0 }, 1200, 'easeInOutExpo');
        return false;
    });

    // Vendor carousel
    $('.vendor-carousel').owlCarousel({
        loop: true, margin: 40, dots: false, autoplay: true, smartSpeed: 1000,
        responsive: { 0:{items:2}, 576:{items:3}, 768:{items:4}, 992:{items:5} }
    });

    // Testimonials carousel
    $(".testimonial-carousel").owlCarousel({
        autoplay: true, smartSpeed: 1500, dots: true, loop: true, center: true,
        responsive: { 0:{items:1}, 576:{items:1}, 768:{items:2}, 992:{items:3} }
    });

})(jQuery);
