// RandomBanner.js
// Displays a banner on a page
// And updates every now and then
// The banner picture needs to be called bannerAd
// and setBanner() needs to be called in the body onLoad tag
// ©2001 AEI Security Ltd
// By Daniel Gorst


// URL to find the banner ad graphics files
baseGraphicsURL = "http://www.stealthbigbrother.com/bannerads/";

// List of filenames of banner graaphics
bannerGraphics = new Array("aei.gif","blue.gif","digisender.jpg","ra.jpg");

// List of links corresponding to above banner ads
bannerLinks = new Array("http://www.aeisecurity.com/","http://www.stealthbigbrother.com/products.html","http://www.digisender.com","http://www.remoteautomation.co.uk");

// Set the number of banners
numberBanners = bannerGraphics.length;

currentLink = 1;		// Starting link
timoutPeriod = 10000;	// Period in milliseconds between banner changes

// Called when page is loaded and calls itself after a period of time

function setBanner() {

	currentLink = generateRandomNumber(numberBanners);

	// currentLink++;
	// if (currentLink > numberBanners) {currentLink = 1;}
	
	document.bannerAd.src = (baseGraphicsURL+bannerGraphics[currentLink-1]);
	currentLink = currentLink;
	window.setTimeout("setBanner();",10000);
}

function clickOnBanner() {
	document.location = bannerLinks[currentLink-1];
}

// Generate a random number between 0 and n

function generateRandomNumber(n) {

	tempRandom = (Math.abs(Math.round(n * Math.random())));
	if (tempRandom < 1) {tempRandom = 1;} 
	return tempRandom;
}
