$(function () {
    'use strict';
    var swiper = new Swiper('.swip-slider', {
        effect: 'coverflow',
        grabCursor: true,
        centeredSlides: true,
        spaceBetween: -30,
        initialSlide: 2,
        coverflowEffect: {
            rotate: 50,
            stretch: 0,
            depth: 150,
            modifier: 1,
            slideShadows: true,
        },
        breakpoints: {
            767: {
                slidesPerView: 2,
            }
        },
        autoplay: {
            delay: 3000,
            disableOnInteraction: false
        },
        pagination: {
            el: '.swiper-pagination',
            dynamicBullets: true,
        }, responsive: {
            0: {
                slidesPerView: 1,
            },
            480: {
                slidesPerView: 1
            },
            768: {
                slidesPerView: 1
            },
            1200: {
                slidesPerView: 3
            }
        }
    });
    var testimonial = new Swiper('.testimonial-slide', {
        direction: 'vertical',
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
        },
    });
    $('.counter-block-value').each(function () {
        var $this = $(this),
                countTo = $this.attr('data-count');
        $({countNum: $this.text()}).animate({
            countNum: countTo
        },
                {
                    duration: 8000,
                    easing: 'linear',
                    step: function () {
                        $this.text(Math.floor(this.countNum));
                    },
                    complete: function () {
                        $this.text(this.countNum);
                    }
                });
    });
    $('.main-menu ul ul').prev('a').addClass('dropdown');
    $('.mob-menu').click(function (e) {
        e.preventDefault();
        $('.main-menu').slideToggle();
        $(this).find('i').toggleClass('fa-bars fa-times');
    });
    $('.justified').each(function () {
        var e = $(this);
        function collage() {
            e.imagesLoaded(function () {
                e.removeWhitespace().collagePlus({
                    'targetHeight': 400,
                    'effect': 'effect-2',
                    'allowPartialLastRow': true
                });
            });
        }
        collage();
        var resizeTimer = null;
        $(window).bind('resize', function () {
            $('.justified a').css("opacity", 0);
            if (resizeTimer)
                clearTimeout(resizeTimer);
            resizeTimer = setTimeout(collage, 200);
        });
    });
    $('[data-background]').each(function () {
        var bg = $(this).attr('data-background');
        if (bg.match('^rgb') || bg.match('^#')) {
            $(this).css('background-color', bg);
        } else {
            $(this).css('background-image', 'url(' + bg + ')');
        }
    });
    $.stellar({
        horizontalScrolling: false,
        responsive: true
    });
    if ($('[data-stellar-background-ratio]').length > 0) {
        setTimeout(function () {
            var st = $(window).scrollTop();
            $(window).scrollTop(st + 1);
            setTimeout(function () {
                $(window).scrollTop(st)
            }, 200)
        }, 200);
    }
    ;
    $('.sscroll').click(function () {
        var ti = $(this).attr('href'),
                tt = $(ti).offset().top - 100;
        $('html, body').animate({scrollTop: tt}, 1000, 'easeInOutExpo');
        return false;
    });
    $('.grid').each(function () {
        var $grid = $(this),
                $item = $grid.children('.grid-item'),
                $itemWide = $grid.children('.grid-item.wide'),
                $itemTall = $grid.children('.grid-item.tall'),
                $cols = $grid.data('columns'),
                $cols = $cols != undefined ? $cols : 3,
                $gutter = $grid.data('gutter'),
                $gutter = $gutter != undefined ? $gutter / 2 : 0;

        $grid.wrap("<div class='grid-wrapper' />");
        $grid.css({
            'margin-left': -$gutter + 'px',
            'margin-right': -$gutter + 'px',
            'margin-top': -$gutter + 'px',
            'margin-bottom': -$gutter + 'px'
        });
        $item.wrapInner("<div class='grid-item-inner' />");
        $grid.find('.grid-item-inner').css({
            'position': 'absolute',
            'top': $gutter,
            'bottom': $gutter,
            'left': $gutter,
            'right': $gutter,
        });

        function itemSizes() {
            $item.width($grid.width() / $cols);
            $item.height($item.width() * 4 / 5);
            $itemTall.height($item.width() * 8 / 5);
            $itemWide.width($grid.width() / $cols * 2);
        }
        itemSizes();
        $grid.isotope({
            itemSelector: '.grid-item',
            masonry: {columnWidth: $grid.width() / $cols}
        });
        $(window).resize(function () {
            itemSizes();
            $grid.isotope({
                masonry: {columnWidth: $grid.width() / $cols}
            })
        }).resize();
    });
//    $(".filter ul li:first-child").addClass("active");
//    $('.grid').isotope({filter: ".cat_16"});
    $('.filter').on('click', 'li', function () {
        var filter = $(this).attr('data-filter');
        $('.grid').isotope({filter: filter});
        $('.filter ul li').removeClass('active');
        $(this).addClass('active');
    });

    $('.filter').on('click', 'li', function () {
        var filter = $(this).attr('data-filter');
        $('.grid-blog').isotope({filter: filter});
        $('.filter ul li').removeClass('active');
        $(this).addClass('active');
    });
    $(window).load(function () {
        $('.masonry').each(function () {
            var $this = $(this);
            $this.imagesLoaded(function () {
                $this.isotope({
                    itemSelector: '.masonry-item'
                });
            });
        });
    });




    // EQUAL-HEIGHT COLUMNS
    // $(window).load(function() {
    $('.equal-height-cols').each(function () {
        var el = $(this).find('[class*="col-"]');
        el.imagesLoaded(function () {
            el.matchHeight({
                byRow: false
            });
        });
    });
    // })

    $('[data-rel^=lightcase]').lightcase({
        maxWidth: 1100,
        maxHeight: 800
    });
    var intenseImages = document.querySelectorAll('.intense');
    if (intenseImages.length)
        Intense(intenseImages);

})
jQuery(document).ready(function () {
    $('#preloader').fadeOut('slow', function () {
        $(this).remove();
    });
});