if (window.addEventListener) window.addEventListener("load", initcps, false);
else if (window.attachEvent) window.attachEvent("onload", initcps);

var DELAY = 5000;
var RESET = 60;
var call_count = 0;

function initcps() {
 setTimeout(rotate, DELAY);
}

function rotate() {
	var ts = new Date().getTime();
	var url = "/js/next_picsharebowl.jsp?" + ts;
	if (call_count % RESET == 0) {
		url += "&reset=true";
		call_count = 0;
	}
	makeRequest(url, handler);
	call_count++;
}

function handler() {
	if (request.readyState == 4) {
		if (request.status == 200) {
			var blah = eval("(" + request.responseText + ")");
			/**
				THE DIVS ARE BACKWARDS, WHICH IS WHY WE ARE PUTTING THE NFC ALBUM IN THE AFC DIV AND VICE-VERSA
			**/
			var el = document.getElementById("afcphotos");
			if (el && blah.nfc) el.style.background = "#000 no-repeat center url(/public-servlet/com.ceiva.servlets.ViewPublicContent?size=full&psb=true&content_id=" + blah.nfc + ")";
			el = document.getElementById("nfcphotos");
			if (el && blah.afc) el.style.background = "#000 no-repeat center url(/public-servlet/com.ceiva.servlets.ViewPublicContent?size=full&psb=true&content_id=" + blah.afc + ")";
		}
		request = null;
		setTimeout(rotate, DELAY);
	}
}
