var iCurrentDYK, iMaxDYK, iDYKSeconds, DYKTimer;

function changeDYK(currentID, newID) {
	if (currentID != newID) {
		oCurrent = $('dyk'+currentID);
		oNew = $('dyk'+newID);

		Effect.Fade(oCurrent, { duration: .5, from: 1.0, to: 0.0, queue: { position: 'end', scope: 'DYK', limit: 4 } });
		Effect.Appear(oNew, {queue: { position: 'start', scope: 'DYK', limit: 4 } });
		iCurrentDYK=newID;

		clearInterval(DYKTimer);
		DYKTimer = setInterval('changeDYK(iCurrentDYK, getNextDYKID())', iDYKSeconds*1000);
	}
}

function getNextDYKID() {
	iCurrentDYK==iMaxDYK ? iCurrentDYK=1 : iCurrentDYK++;
	return iCurrentDYK;
}

Event.observe(window, 'load', function() {
	// Initialize values on page load
	iCurrentDYK = 1; //Start with first DYK
	iMaxDYK = $('didYouKnow').getElementsByTagName('div').length; //Get max number of DYKs based on number of divs in didYouKnow element
	iDYKSeconds = 8; //Number of seconds between rotations

	DYKTimer = setInterval('changeDYK(iCurrentDYK, getNextDYKID())', iDYKSeconds*1000); //Timer to rotate DYKs
});