function nextImage( a ){ if( ! nextImage.images ){ nextImage.images = [...]; nextImage.i = 0; } nextImage.i = (nextImage.i+1) % nextImage.images.length; a.src = nextImage.images[nextImage.i]; }