$(function(){
    // Swipe sur la home avec objectif
    /* var mySwipe = $('#slider').Swipe( {
        startSlide: 0,
        speed: 400,
        auto: 0,
        draggable: false,
        continuous: false,
        disableScroll: false,
        stopPropagation: false,
        callback: function(index, elem, dir) {
            console.log('swipe');
            $('.swipe-controls .btn').each(function(){
                if($(this).hasClass('active')){
                    $(this).removeClass('active');
                }else{
                    $(this).addClass('active');
                }
            });
        },
        transitionEnd: function(index, elem) {}
    }).data('Swipe');
    $('#prev').on('click', function(){
        mySwipe.prev();
    });
    $('#next').on('click', function(){
        mySwipe.next();
    }); */


    // // for test.
    // $('.showbox').remove();

    $('.prev').on('click', function(){
        $('.element').removeClass('visible');
        $('.sport').addClass('visible');
        $('.btn-primary').removeClass('active');
        $(this).addClass('active');
    });
    $('.next').on('click', function(){
        $('.element').removeClass('visible');
        $('.nutrition').addClass('visible');
        $('.btn-primary').removeClass('active');
        $(this).addClass('active');
    });


    /*** Coaching ***/

    $('.slide-day-controls .btn').click(function() {
        $('.slide-day-controls .btn').removeClass('active');
        $(this).addClass('active');
        var day = $(this).data('coaching-day');
        $('.collapsable-periods').removeClass('active');
        $('.collapsable-periods[data-coaching-day=' + day + ']').addClass('active');
    });

    $('body').on('click', '.period-header', function() {
        $(this).closest('.collapsable-period').toggleClass('active');
    });


    /*** Event listeners ***/
    $(window).on('DOMChange', function() {

        // Bind slider if necessary.
        $('.slick-slider:not(.processed)').each(function() {
            var el = $(this);
            if (el.slick !== undefined) {
                el.slick({
                    'infinite': false,
                    'mobileFirst': true,
                    'variableWidth': true,
                    'prevArrow': false,
                    'nextArrow': false,
                });
                el.addClass('processed');
            }
        });

    }).trigger('DOMChange');

});