<img name="myImage" src="image/0.jpg" width="500" height="500">
<script>
var allImages = new Array(10);
var numloaded = 0;
function countImages()
{
if (++numloaded == allImages.length)animate();
}
for(var i = 0; i < 10; i++)
{
allImages[i] = new Image();
allImages[i].onload = countImages;
allImages[i].src = "image/" + i + ".jpg";
}
var currentImage = 0;
var timeoutId = null;
function animate()
{
document.myImage.src = allImages[currentImage].src;
currentImage = (currentImage + 1) % 10;
timeoutId = setTimeout("animate()",2000);
}
</script>
<form>
<input type="button" value="Start" οnclick="if (timeoutId == null) animate();" />
<input type="button" value="Stop" οnclick="if (timeoutId) clearTimeout(timeoutId); timeoutId=null;" />
</form>