var url = urlTempString.split('|');
var caption = captionTempString.split('|');
var linkto_url = imglinkTempString.split('|');
var imagecount = url.length;
var j=0;
var i=0;
var intID;


//Preload image and populate arrays
	var tempPic ="";
	tempPic = new Image();
	for(i=0;i<url.length-1;i++){
		tempPic.src = url[i];
	}

/*function imagecount(url){
	var count = url.length
	return count;
}*/

function rotateIt() {
//Switch pics around
	j++;
	document.getElementById("pic").src = url[j];
	document.getElementById("pic").alt = caption[j];
	document.getElementById("pic_url").href = linkto_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() {
	imagecount = url.length;
	document.getElementById("pic").src = url[0];
	document.getElementById("pic").alt = caption[0];
	document.getElementById("pic_url").href = linkto_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);
	//count=imagecount(url);
	//var mytext ="";
	//mytext = "count"  + count + "j#" + j;
	//alert (mytext);
	j = (j+1) % imagecount;
	//mytext = "count"  + count + "j#" + j;
	//alert (mytext);
	document.getElementById("pic").src = url[j];
	document.getElementById("pic").alt = caption[j];
	document.getElementById("pic_url").href = linkto_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);
	//count=imagecount(url);
	j = (j==0)? imagecount-1 : j-1;
	document.getElementById("pic").src = url[j];
	document.getElementById("pic").alt = caption[j];
	document.getElementById("pic_url").href = linkto_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];
	 }}

// -->