//Variables for top banner display system. advertising entries are hard-coded currently.
var sponsor = 1;
var TotalSponsor = 5;



//Below, you establish the array of files and urls. 

var bottombanners = new Array();
var sidebanners = new Array();

//simply add new lines for new ads, remove old lines for expired ads, and make sure the lines are in numeric sequence.

bottombanners[0] = new Array("../advertising/main/rent.jpg","http://www.bakabanashi.com/arp/advertising.php");
bottombanners[1] = new Array("../advertising/main/bigbang.jpg","http://www.bakabanashi.com/arp/bigbang.php");
bottombanners[2] = new Array("../advertising/main/rpgnow.gif","http://www.rpgnow.com");

sidebanners[0] = new Array("../advertising/side/rentside.jpg","http://www.bakabanashi.com/arp/advertising.php");
//sidebanners[1] = new Array("../advertising/side/lostdest.jpg","http://www.bakabanashi.com/arp/lostdest.php");

//this variable is the ads you have in rotation. simply take the number of the last banners[x] entry above, add 1, and change the value below.

var maxbottomads = 3
var maxsideads = 1

//nothing else in the script needs to be changed. the below bit is the programming that randomly determines which banner to display and makes the necessary changes to show it.
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 pickRandomBottom(){
	if (maxbottomads > 1){
		randomX = rand(maxbottomads);
		randomX = randomX - 1;}
	else {randomX = 0};
	document.getElementById("bottombannertargeturl").setAttribute("href",bottombanners[randomX][1]);
	document.getElementById("bottomadbanner").src = bottombanners[randomX][0];
}

function pickRandomSide(){
	if (maxsideads > 1) {
		randomX = rand(maxsideads);
		randomX = randomX - 1;
	}
	else {randomX = 0};
	document.getElementById("sidebannertargeturl").setAttribute("href",sidebanners[randomX][1]);
	document.getElementById("sideadbanner").src = sidebanners[randomX][0];
}

function bottomPosition() {
	if (!document.getElementById("maincolumn")) {
		a = document.getElementById("maincolumnwide").offsetHeight;
		d = document.getElementById("maincolumnwide").offsetTop;
	} else {
		a = document.getElementById("maincolumn").offsetHeight;
		d = document.getElementById("maincolumn").offsetTop;	
	}
	b = document.getElementById("sidebar").offsetHeight;
	if(a > b) {c = a}
	else {c = b};
	e = c + d;
	document.getElementById("bottombanner").style.top = e + "px";
}

function randomSponsor(){
	sponsor = rand(TotalSponsor);
}

function changeSponsor() {
// Remember to reset the TotalSponsor value at the top of this page to reflect your current number of available advertisers.
// Set this value to the time between rotations, measured in milliseconds (1/1000 of 1 sec.)
	if (sponsor > TotalSponsor) {sponsor = 1};
	target = "ad" + sponsor;
	++sponsor
	workBlock('topbanner',target,'block');
	window.setTimeout('changeSponsor();',5000);
}

function adTimer(){
	if (bottombanneron == "yes"){
		bottomPosition();
		pickRandomBottom();
		document.getElementById("bottombanner").style.display = "block";
	};
	if (sidebanneron == "yes"){
		pickRandomSide();
		document.getElementById("sidebanner").style.display = "block";
	};
	if (topbanneron == "yes" || redtopon == "yes"){
		randomSponsor();
		changeSponsor();
	};
	if (bexchange == "yes"){
		bottomPosition();
		document.getElementById("bottombanner").style.display = "block";
	};
}