function next(items) {
var max = items.length - 1,
i = -1;
return function () {
i = i < max ? i + 1 : 0;
return items[i];
};
}
var imagName = next(['p01', 'p02', 'p03']);
alert('upload/' + imagName() + '.jpg');
alert('upload/' + imagName() + '.jpg');
alert('upload/' + imagName() + '.jpg');
alert('upload/' + imagName() + '.jpg');