var ImageRotator = {

	Images: new Array(),

	

	Current: 1,

	

	TransitionTime: 10000,

	

	Timeout: null,

	

	Id: "rotating-banner",

	

	Start: function() {

		this.Current = Math.floor((Math.random() * (this.Images.length + 1)) + 1);

		this.Transition();

	},

	

	Transition: function() {

		// Increment the image counter

		this.Current++;

		

		// Make sure the image is still in range

		if (this.Current >= this.Images.length)

			this.Current = 1;

		

		// Once the fadeout is complete we change the image and fade back in

		$("#" + this.Id).fadeOut("slow", function() {

			$(this).attr("src", ImageRotator.Images[ImageRotator.Current].src);

			$(this).fadeIn("slow");

		});	

		

		// Set the timeout

		this.Timeout = setTimeout("ImageRotator.Transition();", this.TransitionTime);

	}

}



// Go through each image and add it to the images array

for (var i = 1; i <= 8; ++i) {

	ImageRotator.Images[i] = new Image();

	ImageRotator.Images[i].src = "images/banners/banner" + i + ".jpg";

}



$(document).ready(function() {

	ImageRotator.Start();

});
