//
// Function to randomise image on home page.
function randomImage () {
	var nPicsTotal, nTotal

	nPicsTotal = 6;
	
	//
	// Collect previous value and convert
	nTotal = ReadCookie ("nHomePageImages");	
	if (nTotal > 0) {
		nTotal = parseFloat(nTotal);
	} else {
		nTotal = 0;
	}
	
	//
	// Calculate display image
	if (nTotal==null || nTotal==0) {
		nTotal = 1;
	} else {
		nTotal = (nTotal + 1);
	}	
	if (nTotal > nPicsTotal) nTotal = 1;
	
	//
	// Set cookie for return visit	
	SetCookie ("nHomePageImages",nTotal,5);

	//
	// Set background
	if (document.getElementById("randomImage")) {
		document.getElementById("randomImage").className="equalColumn homeBackImage" + nTotal;
	}

}

// Standard Set Cookie Function
function SetCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();

	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
 	document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}

// Standard Read Cookie Function
function ReadCookie(cookieName) {
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);

 	if (ind==-1 || cookieName=="") return "";
 	var ind1=theCookie.indexOf(';',ind);

 	if (ind1==-1) ind1=theCookie.length;
 	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}


// Attach events
if (window.attachEvent) {
 	window.attachEvent("onload", randomImage);
} else if (window.addEventListener){
 	window.addEventListener("load", randomImage, false);
} else if (document.addEventListener){
 	document.addEventListener('load', randomImage, false);
}
