Do you have a database to work with here?
If so, I'd create a table like this
CREATE TABLE images (
id int(11) NOT NULL auto_increment
image_name varchar(30) NOT NULL
active char(1)
PRIMARY KEY (image_name)
)
Put all your image names in there. They will be assigned an id. On the first image, set active='Y'. So then all you need to do is select the current image, get the next one in line, update it to active, and so forth. If this is viable, and you need help with the code, just lemme know