
function navbar() {
    var distanceY = window.pageYOffset || document.documentElement.scrollTop,
        //menu
        menu_pos = 90,
        menu = $('.header');
    if (distanceY > menu_pos) {
        $('.header').addClass('smaller');
    } else {
        $('.header').removeClass('smaller');
    }
}

window.onload = function () {
    navbar();
    window.addEventListener('scroll', navbar);
}

/*$(document).ready(function(){
    var $swiper_container = $('.swiper-container');
    if($swiper_container.length!=1){
        return;
    }
    const swiper = new Swiper('.swiper-container', {
        spaceBetween: 300,
        centeredSlides: true,
        loop: true,
        loopAdditionalSlides: 1,
        slidesPerView: 'auto',
        freeMode: true,

        // Navigation arrows
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
    });
});*/

$(document).ready(function(){
    $('.act_img img').hide();
    $('.act_img.active  img').show();
    $( ".act_link" ).hover(function() {
        //li
        $('.act_link').removeClass('active');
        $(this).addClass('active');
        //img
        var img = $(this).data('img');
        $('#act_img').attr('style','background:url('+img+') no-repeat center center / cover');
    });
});

$(document).ready(function() {
    var $slider_pdt = $('.slider_pdt');
    if ($slider_pdt.length != 1) {
        return;
    }
    $('.slider_pdt').bxSlider({
        auto: true,
        autoControls: false,
        stopAutoOnClick: true,
        pager: false,
        controls:false,
        adaptiveHeight:true,
    });
});

$(document).ready(function() {
    var $slider_home = $('.home_slider');
    if ($slider_home.length != 1) {
        return;
    }
    $('.home_slider').bxSlider({
        auto: true,
        autoControls: false,
        stopAutoOnClick: true,
        pager: false,
        controls:false,
        adaptiveHeight:false,
        mode:'fade',
    });
});

$(document).ready(function() {
    var $domain_slider = $('.domain_slider');
    if ($domain_slider.length != 1) {
        return;
    }
    $('.domain_slider').bxSlider({
        auto: false,
        autoControls: false,
        stopAutoOnClick: true,
        pager: false,
        controls:true,
        nextSelector: ".btn-next",
        prevSelector: ".btn-prev",
        nextText: '<i class="bi bi-chevron-right"></i>',
        prevText: '<i class="bi bi-chevron-left"></i>',
    });
});

$(document).ready(function() {
    var $news_slider = $('.news_slider');
    if ($news_slider.length != 1) {
        return;
    }
    $('.news_slider').bxSlider({
        auto: false,
        autoControls: false,
        stopAutoOnClick: true,
        pager: false,
        controls:true,
        minSlides: 1,
        maxSlides: 3,
        moveSlides: 1,
        slideWidth: '798px',
        nextSelector: ".swiper-button-next",
        prevSelector: ".swiper-button-prev",
        nextText: '<i class="bi bi-chevron-right"></i>',
        prevText: '<i class="bi bi-chevron-left"></i>',
        onSlideAfter: function (currentSlideNumber, totalSlideQty, currentSlideHtmlObject) {
            $('.active-slide').removeClass('active-slide');
            $('.news_slider .item').eq(currentSlideHtmlObject + 4).addClass('active-slide')
        },
        onSliderLoad: function () {
            $('.news_slider .item').eq(4).addClass('active-slide')
        },

    });
});

//numbers scroll & animation
var a = 0;
$(window).scroll(function() {

    var $nb_container = $('#nb_container');
    if($nb_container.length!=1){
        return;
    }

    var oTop = $('#nb_container').offset().top - window.innerHeight;
    if (a == 0 && $(window).scrollTop() > oTop) {
        $('.counter').each(function() {
            var $this = $(this),
                countTo = $this.attr('data-count');
            $({
                countNum: $this.text()
            }).animate({
                    countNum: countTo
                },
                {
                    duration: 2225,
                    easing: 'swing',
                    step: function() {
                        $this.text(Math.floor(this.countNum));
                    },
                    complete: function() {
                        $this.text(this.countNum);
                    }
                });
        });
        a = 1;
    }
});


$(document).ready(function(){
    //form devis
    $('.top_choice').change(function() {
        name = $(this).attr('id');
        value = $(this).val();
        field = $(this).data('form');
        console.log(name,value,field);
        //update cf7 fields
        $('#'+field+' option[value="'+value+'"]').prop('selected', true);



    });
});

document.querySelectorAll('a[href^="#"]').forEach(anchor => {
    anchor.addEventListener('click', function (e) {
        e.preventDefault();

        document.querySelector(this.getAttribute('href')).scrollIntoView({
            behavior: 'smooth'
        });
    });
});


//slick sliders

$(document).ready(function(){
    $('.slick-news').slick({
        slidesToShow:3,
        slidesToScroll:1,
        infinite: true,
        centerMode: true,
        prevArrow: $('.swiper-button-prev'),
        nextArrow: $('.swiper-button-next'),
        responsive: [
            {
                breakpoint: 992,
                settings: {
                    slidesToShow: 2
                }
            },
            {
                breakpoint: 768,
                settings: {
                    slidesToShow: 1
                }
            }
        ]

    });
});
