rnd.today = new Date();
rnd.seed = rnd.today.getTime();

function rnd(){
	rnd.seed = (rnd.seed*9301+49297)%233280;
	return rnd.seed/(233280.0);
}

function rand(number){
	return Math.ceil(rnd()*number);
}

function classBanner(){
	this.timerID = 0;
	this.tStart = null;
	
	this.delay = 1000;

	this.imageArray = new Array();
	this.linkArray = new Array();
	
	this.count = rand(this.imageArray.length);
	
	this.init = function(){
		document.getElementById(this.image).src = this.imageArray[0];
		document.getElementById(this.link).href = this.linkArray[0];
	}
	
	this.addImage = function(imageToAdd){
		this.imageArray.push(imageToAdd);
	}
	
	this.addLink = function(linkToAdd){
		this.linkArray.push(linkToAdd);
	}
	
	this.updateTimer = function(){
		// do nothing if we have only one banner
		if(this.imageArray.length<2) {
			return;
		}
		if(this.timerID){
			clearTimeout(this.timerID);
			this.clockID = 0;
		}
		if(this.count<this.imageArray.length){
			document.getElementById(this.image).src = this.imageArray[this.count];
			document.getElementById(this.link).href = this.linkArray[this.count];
			this.count++;
		}else{
			this.count = 0;
			document.getElementById(this.image).src = this.imageArray[this.count];
			document.getElementById(this.link).href = this.linkArray[this.count];
		}
	}
	
	this.change = function(){
		this.updateTimer();
	}
	
	this.stop = function(){
		if(this.timerID){
			clearTimeout(this.timerID);
			this.timerID = 0;
		}
		
		this.tStart = null;
	}
}

function stopBanner(bannerObject){
	if(bannerObject.timerID){
		clearTimeout(bannerObject.timerID);
		bannerObject.timerID = 0;
	}
	
	bannerObject.tStart = null;
}

function changeBanner(bannerObject, delay){
	setTimeout(bannerObject + ".init()",1);
	setInterval(bannerObject + ".change()", delay);
}

