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);
}
});