/*/
Slideshow - Used to create one or more slideshows or banner rotations in your document

Usage:
  Copy the following to the <head> section of your document, changing each "your_variable..." to suit your needs

<!-- Start of copy -->
<script type="text/javascript" src="banner_rotation.js"></script>
<script type="text/javascript">//<![CDATA[

// Start of the first banner rotation image array
var your_variable1 = new Array; // required

// First banner
your_variable1[0] = new Image; // required - change "new Image" to "new Array" to NOT preload images
your_variable1[0].src = 'path/to/some_image.gif'; // required
your_variable1[0].link = 'http://www.example.com/some_link_1'; // required

// Second banner
your_variable1[1] = new Image;
your_variable1[1].src = 'path/to/some_image.gif';
your_variable1[1].link = 'http://www.example.com/some_link_2';

// Third banner
your_variable1[2] = new Image;
your_variable1[2].src = 'path/to/some_image.gif';
your_variable1[2].link = 'http://www.example.com/some_link_3';

// Fourth banner
your_variable1[3] = new Image;
your_variable1[3].src = 'path/to/some_image.gif';
your_variable1[3].link = 'http://www.example.com/some_link_4';
// End of the first banner rotation image array


// Start of the second banner rotation image array
var your_variable2 = new Array;

// First banner
your_variable2[0] = new Image;
your_variable2[0].src = 'path/to/some_image.gif';
your_variable2[0].link = 'http://www.example.com/some_link_1';

// Second banner
your_variable2[1] = new Image;
your_variable2[1].src = 'path/to/some_image.gif';
your_variable2[1].link = 'http://www.example.com/some_link_2';
// End of the second banner rotation image array


window.onload = function() {
	new Slideshow(your_variable1, 10, 'banner_loc', 'banner_link');
	new Slideshow(your_variable2, 10, 'banner_loc_side', 'banner_link_side');
	
	// place any other code you wish to run here as well
	// note: if you have an onload in the body tag, e.g., <body onload="some code here">,
	// please move it to here as well, otherwise the slideshow will likely not run
}
//]]></script>
<!-- End of copy -->


<!--
The way to actually run the slideshow is listed above in the "window.onload" section:
	new Slideshow(your_variable1, 10, 'banner_loc', 'banner_link');
	
your_variable1 (required) - the name of your array of images
10 (required) - time between image switches, in seconds
'banner_loc' (required) - unique id of the <img> tag that will hold the images
'banner_link' (required) - unique id of the <a> tag surrounding the <img> tag that will hold the link

-->

/*/

function Slideshow(array, interval, imgID, linkID) {
	randomizeArray(array);
	this.array = array;
	this.current = -1;
	this.max = this.array.length;
	this.img = document.getElementById(imgID);
	if (linkID) this.link = document.getElementById(linkID);
	else this.link = false;
	this.interval = interval * 1000;
	
	this.switchBanner = function() {
		this.current++;
		if (this.current == this.max) this.current = 0;
		this.img.src = this.array[this.current].src;
		if (this.link) this.link.href = this.array[this.current].link;
	}
	this.switchBanner();

	var _this = this;
	setInterval(function() { _this.switchBanner() }, this.interval);
} // END class Slideshow

function randomizeArray(array) {
	var i = array.length;
	if (i == 0) return false;
	while (--i) {
		var j = Math.floor(Math.random() * (i + 1));
		var tempi = array[i];
		var tempj = array[j];
		array[i] = tempj;
		array[j] = tempi;
	}
}