Poznakomlus, вариант...
function next(items) {
var max = items.length,
i = 0;
return function () {
return items[i++ % max];
};
}
var imagName = next(['p01', 'p02', 'p03']);
alert('upload/' + imagName() + '.jpg');
alert('upload/' + imagName() + '.jpg');
alert('upload/' + imagName() + '.jpg');
alert('upload/' + imagName() + '.jpg');