/* put this ABOVE the css so you don't get a flash in content */

function createCookie(name,value,days) {
  
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
 
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

/*function rnd() {
	rnd.today=new Date();
	rnd.seed=rnd.today.getTime();
	
	rnd.seed = (rnd.seed*9301+49297) % 233280;
	return rnd.seed/(233280.0);
	}
	
	function rand(number) {
	return Math.ceil(rnd()*number);
}*/

function switchstyle() {

  var cookie = readCookie("colcap");
  var num = 0;  
    
   //if there is no cookie, or it is null, set the 
  //number to one.  Else just go to the next one
  
	 if ((cookie == "null") || (!cookie) )	{  
			var num = 1;
			createCookie("colcap", 1, 365);
	  }
	
	//if you have been there, set the title to the already-created cookie 
	  else  {
	  
	  		if (cookie < 5) {
				num = parseInt(cookie) + 1;
				createCookie("colcap", num, 365);
			}
			
			else {
				num = 1;
				createCookie("colcap", num, 365);
	 		 }   
	 }
	 
  //set up an array of the titles of the alternate stylebg  
  //var bg = new Array();
	//bg[1] = "deliver";
	//bg[2] = "consulting";
	//bg[3] = "dependability";   
	//bg[4] = "innovative";   
	//bg[5] = "leadership";
    
  
  //generate a random number to pick a random alternate stylesheet
  //arraylen = bg.length;
  //var randombg = rand(arraylen-1);

  var backImage = "url(\/images\/home\/" + "message" + num + ".jpg)";
  var partnerImage = "url(\/images\/home\/" + "partners" + num + ".jpg)";
  var successImage = "url(\/images\/home\/" + "success" + num + ".jpg)";
  
  document.getElementById('message').style.backgroundImage = backImage;
  document.getElementById('partners-header').style.backgroundImage = partnerImage;
  document.getElementById('success-story').style.backgroundImage = successImage;
 
}

// Dean Edwards/Matthias Miller/John Resig

function init() {
	// quit if this function has already been called
	if (arguments.callee.done) return;

	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;

	// kill the timer
	if (_timer) clearInterval(_timer);

	// do stuff
	switchstyle();
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			init(); // call the onload handler
		}
	};
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			init(); // call the onload handler
		}
	}, 10);
}

/* for other browsers */
window.onload = init;



