$(document).ready(function () {
    //товары + новости
    var owlSlidersHome = $(".slider-home");
    console.log(owlSlidersHome.length)
    for(var i = 0; i < owlSlidersHome.length; i++){
        if($(owlSlidersHome[i]).children().length > 1) {

            $(owlSlidersHome[i]).owlCarousel({
                responsiveClass: true,
                responsive: {
                    0: {
                        items: 2,
                        slideBy: 1,
                        loop:true,
                        dots:true
                    },


                    600: {
                        items: 3,
                        slideBy: 1,
                        loop:true,
                        dots:true
                    },


                    768: {
                        items: 3,
                        slideBy: 1,
                        dots:false
                    },

                    992: {
                        items: 4,
                        slideBy: 1,
                        dots:false
                    }
                },
                smartSpeed:250,
                nav:false,


                onInitialize: function(){
                    $(owlSlidersHome[i]).on('initialized.owl.carousel', function(event) {
                        // console.log(event.page.size)
                        // console.log(event.item.count)

                        if(event.page.size < event.item.count){
                            $(owlSlidersHome[i]).parent().parent().find('.btn-l_').addClass('vis_ lock');
                            $(owlSlidersHome[i]).parent().parent().find('.btn-r_').addClass('vis_');
                        } else {
                            $(owlSlidersHome[i]).parent().parent().find('.btn-l_').addClass('disabled');
                            $(owlSlidersHome[i]).parent().parent().find('.btn-r_').addClass('disabled');
                        }
                    })
                }
            })



            $(owlSlidersHome[i]).parent().parent().find(".btn-r_ ").click(function(){
                //console.log('prev');

                if(!($(this).hasClass('lock'))){
                    $(this).parent().parent().find(owlSlidersHome).trigger('next.owl.carousel');
                }

            })

            $(owlSlidersHome[i]).parent().parent().find(".btn-l_").click(function() {
                //console.log('next');
                if(!($(this).hasClass('lock'))){
                    $(this).parent().parent().find(owlSlidersHome).trigger('prev.owl.carousel');

                }
            })

            $(owlSlidersHome[i]).on('changed.owl.carousel', function(event) {
                var index = event.item.index;
                var count = event.item.count;
                var size = event.page.size;

                if(size < count){
                    $(this).parent().parent().find(".btn-l_").addClass('vis_');
                    $(this).parent().parent().find(".btn-r_").addClass('vis_');
                } else {
                    $(this).parent().parent().find(".btn-l_").removeClass('vis_');
                    $(this).parent().parent().find(".btn-r_").removeClass('vis_');
                }

                if(index==(count-size)){
                    $(this).parent().parent().find(".btn-r_").addClass('lock')
                } else {
                    $(this).parent().parent().find(".btn-r_").removeClass('lock')
                }
                if (index==0){
                    $(this).parent().parent().find(".btn-l_").addClass('lock')
                } else  {
                    $(this).parent().parent().find(".btn-l_").removeClass('lock')
                }
            })

            $(owlSlidersHome[i]).on('translated.owl.carousel', function(event) {


            })
        }
    }


    function addCardGallerySlider() {
        if( $(".card-block-wrapp").children().length >= 1 ){
            if($(window).width() <= 550) {
                $(".slider-card").owlCarousel({
                    responsiveClass: true,
                    navSpeed:150,
                    dots:true,
                    nav:true,
                    navText:[],
                    items:1,
                    autoplay:false,
                    loop:true,
                    autoHeight: true,
                    autoHeightClass: 'owl-height',
                    video:true
                });
            } else {
                $(".slider-card").trigger('destroy.owl.carousel');
            }
        }
    }
    addCardGallerySlider();
    $(window).resize(function () {
        addCardGallerySlider();
    })

    $('.title-blocks-home-tabs').click(function () {
        var index_ = $(this).index();
        var tabs = $('.slider-tabs');
        $('.title-blocks-home-tabs').removeClass('active');
        $(this).addClass('active');
        $(tabs).css({display:'none'});
        $(tabs[index_]).css({display:'block'});
        $(tabs[index_]).find('.slider-home').addClass('init').trigger('refresh.owl.carousel');
    })
})



















