function slide() {
    var $slider = $("#slider");

    if ($slider.size() > 0) {
        var sp = $slider.slippry();
    }
}

$(function () {
    slide();

    $(document).on("pjax:end", function() {
        var $slider = $(".slider-container");
        if ($slider.data("live")) {
            slide();
        }
    });

    $modal = $('#slides-modal');
    var interval = $modal.data('interval');
    var slideInterval = $modal.data('slides-interval');
    var time = parseFloat($.cookie('modal-slide'));
    var showModal = true;
    var now = (new Date()).getTime();

    if (interval && interval > 0 && time != null && (time + (1000 * parseFloat(interval))) > now) {
        showModal = false;
    }

    if ($modal.size() > 0 && showModal) {
        $modal.modal('show');

        var slideIndex = 0;
        var timeout = null;
        showSlides();

        function showSlides() {
            var slides = document.getElementsByClassName('slide-modal');
            for (var i = 0; i < slides.length; i++) {
                slides[i].style.display = 'none';
            }
            slideIndex++;
            if (slideIndex > slides.length) {
                slideIndex = 1
            }
            slides[slideIndex - 1].style.display = 'block';
            $('.slide-control').removeClass('active');
            $('.slide-control-' + (slideIndex - 1)).addClass('active');
            timeout = setTimeout(showSlides, 1000 * slideInterval);
        }

        $('.slide-control').click(function (e) {
            var $this = $(this);
            var index = $this.data('index');

            slideIndex = index;
            clearTimeout(timeout);
            showSlides();

            e.preventDefault();
        });

        $.cookie('modal-slide', new Date().getTime());
    }
});