/*
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
*/

/*
This script was edited for personal use by Jemima Pereira.
The original version as adapted to WordPress is available from
http://jemimap.ficml.org/colorpress/
*/

// code from Browser Detect Lite  v2.1
// http://www.dithered.com/javascript/browser_detect/index.html
// modified by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)
// modified by Michael Lovitt to include OmniWeb and Dreamcast
// modified by Jemima Pereira to detect only relevant browsers

var pause = 10;  //start at .1 second pause
var increment = 10; //increase pause to slow script down

function BrowserDetectXLite() {
	var ua = navigator.userAgent.toLowerCase(); 
	this.ua = ua;

	// browser name
	this.isIE        = ( (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) ); 
        this.isSafari      = (ua.indexOf('safari') != - 1);

	// browser version
	this.versionMinor = parseFloat(navigator.appVersion); 
	
	// correct version number for IE4+ 
	if (this.isIE && this.versionMinor >= 4) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
	}
	
	this.versionMajor = parseInt(this.versionMinor); 
	
	// platform
	this.isWin   = (ua.indexOf('win') != -1);
	this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1) );
	this.isMac   = (ua.indexOf('mac') != -1);

	this.isIE4x = (this.isIE && this.versionMajor == 4);
	this.isIE4up = (this.isIE && this.versionMajor >= 4);
	this.isIE5x = (this.isIE && this.versionMajor == 5);
	this.isIE55 = (this.isIE && this.versionMinor == 5.5);
	this.isIE5up = (this.isIE && this.versionMajor >= 5);
	this.isIE6x = (this.isIE && this.versionMajor == 6);
	this.isIE6up = (this.isIE && this.versionMajor >= 6);
	
	this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetectXLite();
//end of browser detector

  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);
*/

	var r = 127;
	var g = 127;
	var b = 127;
	
	// 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 shades
	var p1 = .1;
	var p2 = .15;
	var p3 = .2;
	var d1 = .6;
	var d2 = .75;
	var d3 = .85;
	
	getLighterRGBShades();
	getDarkerRGBShades();
	
	// get random intervals used to calculate the changing RGB values
	var ri = Math.floor(Math.random()*3);
	var gi = Math.floor(Math.random()*3);
	var bi = Math.floor(Math.random()*3);


	// Write out styles with the changeable values that we get
	// from the random rgb values. 
function writeStyle() {
	document.writeln('<style>');
	document.writeln('body{background:rgb('+r+', '+g+', '+b+');}');
	document.writeln('#header{background:rgb('+rd1+', '+gd1+', '+bd1+');}');
	document.writeln('#content{background:rgb('+rp2+', '+gp2+', '+bp2+');}');
	document.writeln('#menu{background:rgb('+rp3+', '+gp3+', '+bp3+');}');
	document.writeln('a{color:rgb('+r+', '+g+', '+b+');}');
	document.writeln('a:hover{color:rgb('+r+', '+g+', '+b+');}');
	document.writeln('a:visited{color:rgb('+r+', '+g+', '+b+');}');
	document.writeln('<\/style>');
	}
  }

// called from body onload
function init() {
	changeLinkColor();
	}
	
// This changes the links and body background color
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;
	getDarkerRGBShades();
	//setStyleByTag('a','color','rgb('+rd2+', '+gd2+', '+bd2+')');
	setStyleByTag('h2','color','rgb('+rd1+', '+gd1+', '+bd1+')');
	setStyleById('menu','color','rgb('+rd2+', '+gd2+', '+bd2+')');
	//hide this one in an if statement to stop IE from flashing
        if (!((browser.isIE55 || browser.isIE6up) && browser.isWin32)) {
           // rotate background color if browser is non-moronic
	   setStyleByTag('body','background','rgb('+r+', '+g+', '+b+')');
	}
	// now lets figure lighter shades and change the background style 
	// property of our banner, centercontent, and rightcontent divs. 
	// If you'd rather they stayed white, just get rid of the next 
	// block of code.
	getLighterRGBShades();
	setStyleById('header','background','rgb('+rp2+', '+gp2+', '+bp2+')');
	//setStyleById('content','background','rgb('+rp2+', '+gp2+', '+bp2+')');
	setStyleById('menu','background','rgb('+rp1+', '+gp1+', '+bp1+')');
	// change the value of setTimeout to speed up or slow down	
	pause += increment;
	// if (pause > 60000) return; // stop script after a while
	setTimeout('changeLinkColor()',pause);
	}

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)));
	}

function getDarkerRGBShades() {
	rd1=parseInt(r*d1);
	gd1=parseInt(g*d1);
	bd1=parseInt(b*d1);
	rd2=parseInt(r*d2);
	gd2=parseInt(g*d2);
	bd2=parseInt(b*d2);
	rd3=parseInt(r*d3);
	gd3=parseInt(g*d3);
	bd3=parseInt(b*d3);
	}

// thanks to randomwalks.com for this code
function targetLinks(boNew) {
	if (boNew) 
		where = "_blank";
	else
		where = "_self";
	for (var i=0; i<=(document.links.length-1); i++) {
		document.links[i].target = where;
		}
	}

// 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);
	//shortlength = Math.min(elements.length, 150);
	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) {
	if (document.getElementById(i)) {
	   var n = document.getElementById(i);
	   n.style[p] = v;
	   }
}

// Now call the function that writes initial STYLE tags to page.
//
//writeStyle(); //don't need it

// By adding this directly to the script, the need for editing BODY tags
// to run the onload function is removed.
//
window.onload = function(e) {
     init();
} 

