(function ($) {
    "use strict";

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


    // Initiate the wowjs
    new WOW().init();


    // Sticky Navbar
    $(window).scroll(function () {
        if ($(this).scrollTop() > 300) {
            $('.sticky-top').addClass('shadow-sm').css('top', '0px');
        } else {
            $('.sticky-top').removeClass('shadow-sm').css('top', '-100px');
        }
    });


    // Back to top button
    $(window).scroll(function () {
        if ($(this).scrollTop() > 300) {
            $('.back-to-top').fadeIn('slow');
        } else {
            $('.back-to-top').fadeOut('slow');
        }
    });
    $('.back-to-top').click(function () {
        $('html, body').animate({ scrollTop: 0 }, 1500, 'easeInOutExpo');
        return false;
    });


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


    // Header carousel
    $(".header-carousel").owlCarousel({
        autoplay: true,
        smartSpeed: 1500,
        items: 1,
        dots: true,
        loop: true,
        nav: true,
        navText: [
            '<i class="fas fa-left-long"></i>',
            '<i class="fas fa-right-long"></i>'
        ]
    });


    // News carousel
    $(".news-carousel").owlCarousel({
        autoplay: true,
        smartSpeed: 1500,
        items: 2,
        dots: true,
        loop: true,
        nav: true,
        navText: [
            '<div class="w-8 h-8 flex items-center justify-center bg-red-600 rounded-md"><i class="fas fa-left-long text-white"></i></div>',
            '<div class="w-8 h-8 flex items-center justify-center bg-red-600 rounded-md"><i class="fas fa-right-long text-white"></i></div>',
        ],
        responsive: {
            0: {
                items: 1.25
            },
            640: {
                items: 2
            },
            768: {
                items: 1.5
            },
            1024: {
                items: 2
            }
        }
    });

    // Staff Carousel
    $(".staff-carousel").owlCarousel({
        autoplay: true,
        smartSpeed: 1500,
        items: 2,
        dots: true,
        loop: true,
        nav: true,
        navText: [
            '<div class="w-8 h-8 flex items-center justify-center bg-red-600 rounded-md"><i class="fas fa-left-long text-white"></i></div>',
            '<div class="w-8 h-8 flex items-center justify-center bg-red-600 rounded-md"><i class="fas fa-right-long text-white"></i></div>',
        ],
        responsive: {
            0: {
                items: 1
            },
            640: {
                items: 2
            },
            768: {
                items: 3
            },
            1024: {
                items: 4
            }
        }
    });

    // Testimonials carousel
    $(".testimonial-carousel").owlCarousel({
        autoplay: true,
        smartSpeed: 1000,
        center: true,
        dots: false,
        loop: true,
        nav: true,
        navText: [
            '<i class="fas fa-left-long"></i>',
            '<i class="fas fa-right-long"></i>'
        ],
        responsive: {
            0: {
                items: 1
            },
            768: {
                items: 2
            }
        }
    });


    // Portfolio isotope and filter
    var portfolioIsotope = $('.portfolio-container').isotope({
        itemSelector: '.portfolio-item',
        layoutMode: 'fitRows'
    });
    $('#portfolio-flters li').on('click', function () {
        $("#portfolio-flters li").removeClass('active');
        $(this).addClass('active');

        portfolioIsotope.isotope({ filter: $(this).data('filter') });
    });


})(jQuery);

