(function ($) {
    'use strict';

    function homeSlide() {
        $('.slide-carousel').owlCarousel({
            loop: true,
            autoplay: true,
            margin: 10,
			delay:3000,
            dots: true,
            responsive: {
                0: {
                    items: 1
                },
                600: {
                    items: 1
                },
                1000: {
                    items: 1
                }
            }
        })
    }
    homeSlide()


    // FOR PRICE FILTER
    function priceFilter(){
        var postFilter = $('.filter-init');
        $.each(postFilter, function (index, value) {
            var el = $(this);
            var parentClass = $(this).parent().attr('class');
            var $selector = $('#' + el.attr('id'));
            $($selector).imagesLoaded(function () {
                var festivarMasonry = $($selector).isotope({
                    itemSelector: '.filter-item',
                    percentPosition: true,
                    masonry: {
                        columnWidth: 0,
                        gutter: 0
                    }
                });
                $('.collapse').on('shown.bs.collapse hidden.bs.collapse', function () {
                    festivarMasonry.isotope('layout');
                });
                $(document).on('click', '.' + parentClass + ' .tab-filter a', function () {
                    var filterValue = $(this).attr('data-filter');
                    festivarMasonry.isotope({
                        filter: filterValue,
                        animationOptions: {
                            duration: 450,
                            easing: "linear",
                            queue: false,
                        }
                    });
                    return false;
                });
                $('.filter-wrapper .tab-filter a:first-child').click();
            });
        });
    }
    priceFilter()
    $(document).on('click', '.tab-filter a', function () {
        $(this).siblings().removeClass('active');
        $(this).addClass('active');
    });



    // counter up
    $('.counter').counterUp({
        delay: 10,
        time: 1000
    });

    // mobile size
    function menuSmall() {
    $(".dropdown-toggle").on("click", function(e) {
        if (window.innerWidth <= 991) {
            e.preventDefault();
            $(this).parent().toggleClass("current");
            $(this).next().slideToggle();
        }
        });
    }
    menuSmall()

    //  scrollingup
    function scrolltop() {
        $(window).on('scroll', function () {
            if ($(this).scrollTop() > 200) {
                $('.scrollingUp').addClass('is-active');
            } else {
                $('.scrollingUp').removeClass('is-active');
            }
        });
        $('.scrollingUp').on('click', function () {
            $("html, body").animate({
                scrollTop: 0
            }, 600);
            return false;
        });
    }
    scrolltop()


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


    //  masonary
    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()


})(jQuery);