var url = urlTempString.split('|');
var caption = captionTempString.split('|');
var count = url.length;
var j=0;
var intID;

//Preload image and populate arrays

	tempPic = new Image();
	for(i=0;i<url.length-1;i++){
		tempPic.src = url[i];
	}

function rotateIt() {

//Switch pics around

	j++;
	document.getElementById("pic").src = url[j];
	var ns4 = document.layers;
	
	if (ns4) {
  		document.captions.document.open();
  		document.captions.document.write(caption[j]);
  		document.captions.document.close();
 	} else {
 		document.getElementById("captions").innerHTML = caption[j];
	}
	
	if(j>=url.length-1) {
		j=-1;
	}
}


//Start function

function startIt() {

	document.getElementById("pic").src = url[0];
	var ns4 = document.layers;

	if (ns4) {

  		document.captions.document.open();
  		document.captions.document.write(caption[0]);
  		document.captions.document.close();
 	} else {
  		document.getElementById("captions").innerHTML = caption[0];
	}
	intID = setInterval('rotateIt()',10000);
}


//Go forward

function next() {

	clearInterval(intID);
	j = (j+1) % count;
	document.getElementById("pic").src = url[j];
	var ns4 = document.layers;

	if (ns4) {

  		document.captions.document.open();
  		document.captions.document.write(caption[j]);
  		document.captions.document.close();

 	} else {
  		document.getElementById("captions").innerHTML = caption[j];
	}
}


//Go Back

function prev() {

	clearInterval(intID);
	j = (j==0)? count-1 : j-1;
	document.getElementById("pic").src = url[j];
	var ns4 = document.layers;

	if (ns4) {

  		document.captions.document.open();
  		document.captions.document.write(caption[j]);
  		document.captions.document.close();

 	} else {
  		document.getElementById("captions").innerHTML = caption[j];
	}
}
