
var image = new Array();
var pictureCount = 0;

function _imageStart(){
 _swap(0);
}

function _addImage(image_name_element, caption){
 image[image.length] = new Image(500, 500);
 image[image.length-1].src = image_name_element;
 image[image.length-1].caption = caption;
}

function _back(){
 --pictureCount;
 if (pictureCount<0) pictureCount = image.length-1;
 _swap(pictureCount);
}

function _forward(){
 ++pictureCount;
 if (pictureCount>=image.length) pictureCount = 0; 
 _swap(pictureCount);
}

function _swap(input){
 pictureCount = input;
 document.getElementById("image").src = image[pictureCount].src;
 document.getElementById("caption").innerHTML = image[pictureCount].caption;
}

//preload images
function preloadImages() {
  var d=document; if(d.images){ if(!d.pre) d.pre=new Array();
    var i,j=d.pre.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.pre[j]=new Image; d.pre[j++].src=a[i];}}
}
