hi i have been following a tutorial on how to build a image viewer using javascript for a web page i am building for my shop. i have not been able to get it to work and i have looked at the comments at the bottom and it seems to work for everyone else. the code could be old i have had to fix one or two things with it being outdated.
this is simply a test for the real thing and have built a html test page and put it on a free hosting site which is
here is the code for the html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>image viewer test page</title>
<script type="text/javascript" src="image.js"></script>
</head>
<body>
<img name="slideImg" src="images/01.jpg" width="800" />
<a href="#" onCLick="switchImage('slideImg')">play</a>
<a href="#" onCLick="clearTimeout(timerID)">pause</a>
<a href="#" onClick="switchImage('slideImg'); clearTimeout(tmierID)">next</a>
</body>
</html>
here is the javascript code file name image.js
var interval = 1500;
var random_display = 0;
var imageDir = "images/";
var imageNum = 0;
var totalImages = imageArray.length;
imageArray = new Array();
imageArray[imageNum++] = new imageItem(imageDir + "01.jpg");
imageArray[imageNum++] = new imageItem(imageDir + "02.jpg");
imageArray[imageNum++] = new imageItem(imageDir + "03.jpg");
imageArray[imageNum++] = new imageItem(imageDir + "04.jpg");
function imageItem(image_location) {
this.image_item = new image();
this.image_item.src = image_location;
}
function get_ImageItemLocation(imageObj) {
return(imageObj.image_item.src);
}
function randNum(x, y) {
var range = y - x + 1;
return Math.floor(Math.random() * range) + x;
}
function getNextImage() {
if (random_display) {
imageNum = randNum(0, totalImages-1);
}
else {
imageNum = (imageNum+1) % totalImages;
}
var new_image = get_ImageItemLocation(imageArray[imageNum]);
return (new_image);
}
function getPrevImage() {
imageNum = (imageNum-1) % totalImages;
var new_image = get_ImageItemLocation(imageArray[imageNum]);
return(new_image);
}
function pervImage(place) {
var new_image = getPrevImage();
document[place].src = new_image;
}
function switchImage(place) {
var new_image = getNextImage();
document[place].src = new_image;
var recur_call = "switchImage('"+place+"')";
timerID = setTimeout(recur_call, interval);
}
any help with this would be good or a pointer to a tutorial that works would be good. once i have the test one working i will then change the code to work how i will need it to