const $links = $('.small a');
let currentIndex = null;
function setActiveImage(index) {
currentIndex = (index + $links.length) % $links.length;
$('.big img').attr('src', $links.eq(currentIndex).attr('href'));
$('.photo').text(`${currentIndex + 1} / ${$links.length}`);
}
$links.click(e => (e.preventDefault(), setActiveImage($links.index(e.currentTarget))));
$('#prev').click(() => setActiveImage(currentIndex - 1));
$('#next').click(() => setActiveImage(currentIndex + 1));
setActiveImage(0);