/*
Unless otherwise indicated, all code below was written by Eric Costello,
and you are free to use, modify and distribute it. Please leave this 
comment block intact so that people can find the original unmodified
version at: http://www.glish.com/css/blogger/

Also see:
http://www.schwa.com
http://www.glish.com
*/

if (document.getElementById) { // kosher

	// get random RGB values so we can change background and link colors
	var r = Math.floor(Math.random()*241);
	var g = Math.floor(Math.random()*241);
	var b = Math.floor(Math.random()*241);
	
	// variables to hold the lighter shade RGB values
	var rp1, gp1, bp1, rp2, gp2, bp2, rp3, gp3, bp3;
	
	//we'll use these values to calculate lighter shades
	var p1 = .1;
	var p2 = .15;
	var p3 = .2;
	
	getLighterRGBShades();
	
	// get random intervals used to calculate the changing RGB values
	var ri = Math.floor(Math.random()*5);
	var gi = Math.floor(Math.random()*5);
	var bi = Math.floor(Math.random()*5);


	// lets write out styles with the changeable values that we get from the cookies
	// and the random rgb values. This will make the page display
	document.writeln('<style>');
	document.writeln('body{background:rgb('+r+', '+g+', '+b+');}');
	document.writeln('div{color:rgb('+r+', '+g+', '+b+');}');
	document.writeln('</style>');
	}

// called from body onload
function init() {
	changeLinkColor();
	}
	

// This changes the links and body background coor
function changeLinkColor() {
	if (!document.getElementsByTagName) {return false;} // unclean! unclean!
	if (r>239||r<1) ri=ri*-1;
	if (g>239||g<1) gi=gi*-1;
	if (b>239||b<1) bi=bi*-1;
	r+=ri;
	g+=gi;
	b+=bi;
	setStyleById('body','background','rgb('+r+', '+g+', '+b+')');
	setStyleById('div','color','rgb('+r+', '+g+', '+b+')');
	setTimeout('changeLinkColor()',400);
	}

function getLighterRGBShades() {
	rp1=parseInt((r*p1)+(255-(255*p1)));
	gp1=parseInt((g*p1)+(255-(255*p1)));
	bp1=parseInt((b*p1)+(255-(255*p1)));
	rp2=parseInt((r*p2)+(255-(255*p2)));
	gp2=parseInt((g*p2)+(255-(255*p2)));
	bp2=parseInt((b*p2)+(255-(255*p2)));
	rp3=parseInt((r*p3)+(255-(255*p3)));
	gp3=parseInt((g*p3)+(255-(255*p3)));
	bp3=parseInt((b*p3)+(255-(255*p3)));
	}

// These 2 setstyle functions were modified from code by Steven Champeon found at
// http://developer.apple.com/internet/_javascript/styles.html

// setStyleByTag: given an element type, style property and value
// args:
//  e - element type or id
//  p - property
//  v - value
function setStyleByTag(e, p, v) {
	var elements = document.getElementsByTagName(e);
	for(var i = 0; i < elements.length; i++) {
		elements.item(i).style[p] = v;
		}
	}

// setStyleById: given an element id, style property and 
// value, apply the style.
// args:
//  i - element id
//  p - property
//  v - value
// 
function setStyleById(i, p, v) {
	var n = document.getElementById(i);
	n.style[p] = v;
}
