var top = 150;		//Controls the intensity of the colors
var topCounter = 0;

/* We have to start at some color, so let's start here. */
var redval = 0;		//Sets up the initial red value
var greenval = top;	//Sets up the initial green value
var blueval = 0;	//Sets up the initial blue value

/* The starting positions of the colors in the controller array */
/* These determine how the intensity of the three colors is changing */
var redpos = 3;		//Beginning the first period of bottom
var greenpos = 1;	//Beginning the second period of top
var bluepos = 5;	//Beginning the rise

//These are the arrays of links and titles on the page. They should change color too
var allLinks = new Array();
var allTitles = new Array();

//This array holds the pattern inherent to moving around the color wheel
//It is used like a loop. After the iterators leave the 6th position (index 5)
//they are brought back around to the 1st position again (index 0)
var controller = [0,0,-1,0,0,1];

function tweakColor() {
	//Set the color of everything we're setting
	var colorString = "rgb("+redval+","+greenval+","+blueval+")";

	if (topCounter % 3 == 0) {
		document.body.style.background = colorString;
		for (var k = 0; k < allLinks.length; k++) {
			allLinks[k].style.color = colorString;
		}
		for (var j = 0; j < allTitles.length; j++) {
			allTitles[j].style.color = colorString;
		}
	}	
	
	//Switch the values to their next values
	redval += controller[redpos];
	greenval += controller[greenpos];
	blueval += controller[bluepos];

	//Shift through the controller array if necessary
	if (topCounter == top - 1) {
		//We've gone through the loop the right number of times, so reset the counter
		topCounter = 0;	//Reset
		
		//Now that we've done that number of iterations, shift the array positions
		if (++redpos == controller.length) { redpos = 0; }
		if (++bluepos == controller.length) { bluepos = 0; }
		if (++greenpos == controller.length) { greenpos = 0; }
		
	} else {
		//Count the number of iterations this time through;
		topCounter++;
	}

	
	//Wait a bit before setting it again.
	setTimeout("tweakColor();", 333);
}
