function aPage(ratio, url){
	this.ratio = ratio;
	this.url = url;
}

var pagesToShow = new Array(
	new aPage( 3, "http://www.cbxclub.com/forum/viewforum.php?f=60"), //classifieds
	new aPage(10, "http://www.cbxclub.com/goodies.html"), //Goodies
	new aPage(20, "http://www.cbxclub.com/forum/index.php?c=8#top2"), // Tech Lib
	new aPage( 4, "http://www.cbxclub.com/forum/viewforum.php?f=48"), //polls
	new aPage(20, "http://www.cbxclub.com/forum/viewforum.php?f=6#top2"), // Msg Board
	new aPage( 7, "http://www.cbxclub.com/forum/viewforum.php?f=60"), //classifieds
	new aPage( 2, "http://www.cbxclub.com/mainx.html"), // Main Page
	new aPage(30, "photos") // Photos
//	new aPage(25, "http://www.cbxclub.com/forum/viewtopic.php?t=2873#15872"), // Bennington Rally To Do
//	new aPage(25, "http://www.cbxclub.com/forum/viewtopic.php?t=2872#15871") // Bennington Rally Schedule
);
// Put all pages into one array so we can just pick a random number and show that page.
var pages = new Array();
var counter = 0;
for (var i = 0; i<pagesToShow.length; i++)
{
	for (var j = 1; j<=pagesToShow[i].ratio; j++)
	{
		pages[pages.length]=pagesToShow[i].url;
	}
}
//alert(top.frames[2].location.href);

var prior_href = "none";
var ids = new Array(0,1);
var current_id = 0;

function changePage(which){
	var show_href = pages[which];
	//Show random photo URL.
	if(show_href == "photos"){
		show_href = getPhotoURL();
	}
	if(top && top.frames && top.frames[2]){
            try{
                if(top.frames[2].location.href){
                     current_href = top.frames[2].location.href;
                }
            } catch (err){
                current_href = "unknown";
            }
            if(current_href != show_href){
			   top.frames[2].location.href = show_href;
			   prior_href = show_href;
            }
	}
//Show a new page every 5 minutes.
//	ids[current_id] = window.setTimeout ("changePage(" + getRandom() + ")", (60000*5));
//	current_id = (current_id == 0 ? 1 : 0);
}
function getRandom(){

    var rand = parseInt(((Math.random()*(pages.length-1))),10);
    while(pages[rand] == prior_href){
        rand = parseInt(((Math.random()*(pages.length-1))),10);
    }
    return rand;
}
function getNumberFromTime(){
	var date = new Date;
	return ((date.getHours() * 4) + parseInt((date.getMinutes()/15)+1,10))-1;
}
// This line based the url shown on the client's system time.
//ids[current_id] = window.setTimeout ("changePage(" + getNumberFromTime() + ")", 0);
// This line just shows a random URL based on the ratios.
ids[current_id] = window.setTimeout ("changePage(" + getRandom() + ")", 0);

// START RANDOM PHOTO CODE
var photoCats = new Array(1,2,3,4); // Photo category ids
var photoPages= new Array(60,23,7,7);  // The number of pages in each

function getPhotoURL(){
// This worked, but gave equal weight to each album instead of each page.
//    var cat = parseInt(((Math.random()*photoCats.length)),10); // Determine which category we'll show
//	var page = parseInt(((Math.random()*photoPages[cat])),10); // Determine which page we'll show
//	var start = ((page+1)*10)-10; // Photos get displayed based on the photo #, not the page # so determine which photo should start the page.
//	var url = "/forum/album_cat.php?cat_id=" + (cat+1) + "&sort_method=pic_time&sort_order=DESC&start=" + start;
//	return url;

	var cat = 0;
	var page = 0;

	var totalPhotoPages = 0;
	for (var i = 0; i < photoCats.length; i++)
	{
		totalPhotoPages += photoPages[i];
	}
	var tempPage = parseInt((((Math.random()%1)*(totalPhotoPages-1))),10); // Determine which page out of all the pages we'll show

	var temp = 0;
	var gotit = false;
	for (var i = 0; i < photoCats.length; i++)
	{
		if(gotit == false){
			if(tempPage <= photoPages[i] + temp){
				page = tempPage - temp;
				cat = i;
				gotit = true;
				break;
			} else {
				temp += photoPages[i];
			}
		}
	}
	var start = ((page+1)*10)-10; // Photos get displayed based on the photo #, not the page # so determine which photo should start the page.
	var url = "/forum/album_cat.php?cat_id=" + (cat+1) + "&sort_method=pic_time&sort_order=DESC&start=" + start;
	return url;
	
}
// END RANDOM PHOTO CODE.