HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/zuiderbos.komma.pro/wwwroot/js/overviewSlider.js
/**
 * Created by Pascal on 16/06/17.
 */

$(function () {

    var index = 0;
    var maxIndex = 1;

    $(function(){
        initSlider();
    });

    function initSlider() {
        index = 0;
        maxIndex = $('.image-slider figure .image').length - 1;


        $('.image-slider figure .image-slider-nav .nav-button').click(function () {
            index = $(this).data('image');
            setImage();
            resetInterval();
        });

        //reset interval if already has been set, because of the ajax content pages
        if(typeof loopAnimation !== 'undefined') clearInterval(loopAnimation);

        loopAnimation = setInterval(function () {
            nextImage();
        }, 4000);

        if( typeof $.swipe === "undefined") rebindTouchSwipe();

        $('figure').swipe({
            swipeLeft: function () {
                nextImage();
                resetInterval();
            },
            swipeRight: function () {
                index--;
                setImage();
                resetInterval();
            }
        });
    }

    function resetInterval() {
        clearInterval(loopAnimation);
        loopAnimation = setInterval(nextImage, 5000);
    }

    function nextImage() {
        index++;
        setImage();
    }

    function setImage() {

        var previousIndex = index - 1;
        var nextIndex = index + 1;

        if(previousIndex <= -1) previousIndex = maxIndex;
        if(nextIndex > maxIndex) nextIndex = 0;

        if(maxIndex < index) index = 0;
        if(index < 0) index = maxIndex;



        $('.image-slider figure .image').removeClass('active');

        $('.image-slider figure .image[data-image="' + index + '"]').addClass('active');
        $('.image-slider figure .image-slider-nav .previous').data('image', previousIndex);
        $('.image-slider figure .image-slider-nav .next').data('image', nextIndex);

    }

});