function count_images()
{
	if (++num_loaded_images == num_images)
	animate() ;
}

var num_loaded_images = 0 ;
var aniframes = new Array(num_images) ;
for (var i = 0; i < num_images; i++)
{
	aniframes[i] = new Image();                // Create an off-screen image
	aniframes[i].src = base_image + i + ".jpg";  // Tell it what URL to load.
	aniframes[i].onload = count_images;  
}

var frame = 0;         // The frame counter: keeps track of current frame.
var rand_no = Math.floor(Math.random()*num_images);
frame = (rand_no)%num_images;             // Update the frame counter
var timeout_id = null; // Allows us to stop the animation with clearTimeout()


// This function performs the animation.  Call it once to start.
// Note that we refer to the on-screen image using its name attribute.
function animate()
{
	document.animated_image.src = aniframes[frame].src; // Display the current frame
	frame = (frame + 1)%num_images;             // Update the frame counter
	timeout_id = setTimeout("animate()", animation_interval);  // Display next frame later.
}
