function loadNextImage() {
	//get Element with rotating background
	var myElement = document.getElementById('innerwrapper');

	//declare background image directory path and image array
	var thePath = "/wordpress/wp-content/themes/shr2008/images/random_bgs/home/";
	var theImages = new Array();
	theImages[0] = "home1.jpg";
	theImages[1] = "home2.jpg";
	theImages[2] = "home3.jpg";
	
	//get current cookie value
	var currentIndex = parseInt(getCookie());
	var imgPath = thePath + theImages[currentIndex];
	
	//apply background image to Element
	myElement.style.background = '#25221e url(' + imgPath + ') no-repeat left top';
	
	//set next cookie index
	currentIndex += 1;
	if(currentIndex > (theImages.length - 1)) {
		currentIndex = 0;
	}
	setCookie(currentIndex);
}

function setCookie(someint) {
	var now = new Date();
	var addDays = now.getDate() + 7
	now.setDate(addDays); // cookie expires in 7 days
	var theString = 'imgID=' + escape(someint) + ';expires=' + now.toUTCString();
	document.cookie = theString;
}

function getCookie() {
	var output = "0";
	if(document.cookie.length > 0) {
		var temp = unescape(document.cookie);
		temp = temp.split(';');
		for(var i = 0; i < temp.length; i++) {
			if(temp[i].indexOf('imgID') != -1) {
				temp = temp[i].split('=');
				output = temp.pop();
				break;
			}
		}
	}
	return output;
}

addLoadEvent(loadNextImage);
