function Banner(src, alt, href) {
	this.PreloadedImage = new Image(); // Preload the banner images
	this.PreloadedImage.src = src;
	this.src = src;
	this.alt = alt;
	this.href = href;
}

function BannerRotator() {
	var Banners = new Array();
	
	this.interval = 30; // Rotation interval in seconds
	this.random = false; // When true, a random banner is displayed each interval
	
	function getRandomNumber() {
		return Math.floor(Math.random() * Banners.length); // Returns a random number between 0 and the length of the Banners array
	}

	this.addBanner = function(src, alt, href) {
		var NewBanner = new Banner(src, alt, href);
		Banners[Banners.length] = NewBanner;
	}

	this.rotate = function(n) {
		if (!n)
			n = (this.random ? getRandomNumber() : 0); // If random is enabled, get a random number, else start off with 0
		else if (n == Banners.length)
			n = 0;
	
		document.getElementById("banner_url").setAttribute("href", Banners[n].href);
		document.getElementById("banner_image").setAttribute("src", Banners[n].src);
		document.getElementById("banner_image").setAttribute("alt", Banners[n].alt);

		n++;
		window.setTimeout("BannerRotator.rotate(" + (this.random ? getRandomNumber() : n) + ")", (this.interval * 1000)); // Timeout for next banner
	}
	
	this.drawBanner = function() {
		var n = getRandomNumber(); // Start off with a random number
		document.write("<a href=\"" + Banners[n].href + "\" id=\"banner_url\"><img src=\"" + Banners[n].src + "\" alt=\"" + Banners[n].alt + "\" id=\"banner_image\" /></a>"); // Write anchor and image
		this.rotate(n); // Start rotation
	}
}