(function(){

    var slider;	
    var sliderOptions = {
        perPage: 3,
        gap: 30
    };	

    function mountSlider(){
        slider = new Splide( '.splide', {
            type: 'loop',
            perPage: sliderOptions.perPage,
            perMove: 1,
            rewind : true,
            pagination: false,
            gap: sliderOptions.gap
        } ).mount();
    }

    function destroySlider(){
        slider.destroy(completely = true);
    }

    function resizeWindow(){
        var sliderSize = document.querySelector('.slider-size').dataset.sliderSize;
        var windowSize = document.body.clientWidth;				
        sliderOptions = null;				
        if ( windowSize > 1000 && sliderSize != 'md' ) {
            sliderOptions = {
                perPage: 3,
                gap: 30
            }
            document.querySelector('.slider-size').dataset.sliderSize = 'md';
        }
        if ( ( windowSize > 768 && windowSize <= 1024 )  && sliderSize != 'sm') {
            sliderOptions = {
                perPage: 2,
                gap: 10
            }
            document.querySelector('.slider-size').dataset.sliderSize = 'sm';
        }							
        if ( windowSize <= 768  && sliderSize != 'xs') {
            sliderOptions = {
                perPage: 1,
                gap: 0
            }
            document.querySelector('.slider-size').dataset.sliderSize = 'xs';
        }
        if (sliderOptions) {
            destroySlider();
            mountSlider();
        }
    }

    if (document.querySelector('.splide')) {
        mountSlider();
        resizeWindow();
        window.onresize = resizeWindow;
    }

})();

function scrollToCalendar() {
    event.preventDefault();
    var scrollContCoords = document.querySelector('.pc-calendar-desktop').getBoundingClientRect().top;
    var scrollCoords = window.pageYOffset + scrollContCoords + 15;
    window.scrollTo(0, scrollCoords);
}

