You could have a look at a simple CGI slide-show example I wrote earlier - 312442, where it cycles through the list instead of stopping at the first and last images.
And you could display greyed out button image instead of generating a submit button when you reach the start and end of the sequence.