


imageList = [
	{ "caption":"Something to crow about",         "path":"backgrounds/rooster.png"   },
	{ "caption":"A substantial start to your day", "path":"backgrounds/oatmeal.png"   },
	{ "caption":"Stacked with local news",         "path":"backgrounds/flapjacks.png" },
	{ "caption":"A strong shot of local news",     "path":"backgrounds/coffee.png"    }
];

imageObjects = [];

function imageLoad(i) {
	if (i < imageList.length) {
		imageObjects[i] = new Image();
		imageObjects[i].nextI = i+1;
		imageObjects[i].onload  = function() { imageLoad(this.nextI); };
		imageObjects[i].src = imageList[i].path;
	} else {
		imageObjects[i-1].nextI %= imageList.length;
	}
}

//Kickoff the image loading process.
imageLoad(0);

token = 1;

window.setInterval(
	function () {
		if ((typeof(imageObjects[token].complete) == "undefined")  || imageObjects[token].complete) {
			document.getElementById('content').style.backgroundImage = "url('" + imageList[token].path + "')";
			document.getElementById('imagecaption').innerHTML = imageList[token].caption;
			token += 1;
			token %= imageList.length;
		}
	},
	5000
)
