
function randomNumber(limit) {
	return Math.floor(Math.random()*limit);
}


function slideImage(imgCount,imgName,imgArr,timerID) {
	var imgSrc, imgAlt, r, timer;
	// get image no
	if (imgCount > imgArr.length-1) {
		imgCount = 0;
	}
	// get and set image details and change image
	imgSrc = imgArr[imgCount];
	imgAlt = imgArr[(imgCount)+1];
	if (document.images) {
		document.images[imgName].src = imgSrc;
	} else {
		document.getElementById(imgName).src=imgSrc;
	}
	// set next image no
	if (imgCount < imgArr.length) {
		imgCount = imgCount + 2;
	}
	// recreate image array
	listCount = 0;
	arrList = "";
	while (listCount < imgArr.length) {
		arrItem = imgArr[listCount];
		arrList = arrList + "'" + arrItem + "'";
		if (listCount != imgArr.length-1) {
			arrList = arrList + ",";
		}
		listCount = listCount + 1;
	}
	// do again
	timer = 0;
	if (timerID != '') {
		clearTimeout(timer);
	}
	timerNewID = imgName;
	setFunction = "slideImage(" + imgCount + ",'" + imgName + "',[" + arrList + "],'" + timerNewID + "')";
	timer = setTimeout(setFunction, 5000);
}

// randomImage(['0.gif','filename0','1.gif','filename1','2.gif','filename2']); 
function randomImage(imgName,imgArr) {
	var imgSrc, imgAlt, r, timer;
	// get and set image details and change image
	r = randomNumber(imgArr.length / 2);
	imgSrc = imgArr[r * 2];
	imgAlt = imgArr[(r * 2)+1];
	if (document.images) {
		document.images[imgName].src = imgSrc;
	} else {
		document.getElementById(imgName).src=imgSrc;
	}
	// recreate image array
	listCount = 0;
	arrList = "";
	while (listCount < imgArr.length) {
		arrItem = imgArr[listCount];
		arrList = arrList + "'" + arrItem + "'";
		if (listCount != imgArr.length-1) {
			arrList = arrList + ",";
		}
		listCount = listCount + 1;
	}
	// do again
	timer = 0;
	clearTimeout(timer);
	setFunction = "randomImage('" + imgName + "',[" + arrList + "])";
	timer = setTimeout(setFunction, 1000);
}


