// JavaScript Document
/*

Slide show image rotator

(a) change variable vc_image_change_speed to suit the speed you want
(b) include this script via "<script src='vc_slideshow.js'></script> 

(b) call vc_preload_images() like this -> vc_preload_images( '01.gif', '02.gif' )
using whatever images you want to use - ensure to use a full path if necessary

(c) ensure the image that you want totated is named and already in the HTML document as

<img name="vc_changing_image" src = (*whatever initial source you want to use *) ...
it will be altered quickly

(d) execute the slideshow: <script>	vc_set_next_random(); vc_slideshow_play();</script>
(use vc_set_next_random() to randomized the first image shown)

change_speed is how fast you want the images to change in milliseconds          

*/

/* image rotator functions */

var vc_image_list;
var vc_timer;
var change_speed = 500;
var last_index = 0;
var n_image_elements;

function vc_preload_images()
{ 
  var args = vc_preload_images.arguments;
  vc_image_list = new Array(args.length);
  for(var i=0; i < args.length; i++)
  {
    vc_image_list[i] = new Image;
    vc_image_list[i].src = args[i];
  }

   n_image_elements = vc_image_list.length	

}

// provides a random index number to a set of images
function vc_select_random_image() {
		return Math.round(Math.random() * (n_image_elements - 1));	
}

function vc_set_next(number) {
   if (number > (n_image_elements - 1)) {
	last_index = 0
	}
   else {
	last_index = number
   }
}

function vc_set_next_random() {
	vc_set_next(vc_select_random_image())
}

// displays the next image in order, based on whatever the last_index_value is
function vc_show_next() {
   // loop it from 0 to (n_image_elements - 1)
   if (last_index >= n_image_elements)
		last_index = 0

  if (document.images) {
      document.images["vc_changing_image"].src = vc_image_list[last_index].src;
	}
	last_index++;
}

// plays sequence in order
function vc_slideshow_play() {
	   vc_show_next();
	   vc_timer = setTimeout("vc_slideshow_play()", change_speed);
}



