My function so far:
var img = ;
img.push('images/educational/img3-large.jpg, caption for this image');
img.push('images/educational/img2-large.jpg, caption for this image');
img.push('images/educational/img4-large.jpg, caption for this image');
document.getElementById('caption').innerHTML = img[which].split(', ');
the HTML is:
notice that in this sample i create an array that contain a string. each entry is composed of the image url separated with a comma and a white space followed by the caption. i would prefer this approach, so you don't have to go different part of the document when you want to update which image to show. if you want to change an image position on the array, you simply move the line img.push(...) to the desired position.