if (!jQuery){
	var errMsg="jQuery is required for this script to work properly. Please install jQuery 1.3 or higher.";
	alert(errMsg);
	throw new Error(errMsg);
}

$(document).ready(function(){

	// alert("ready");

	function switchSpotlight() {
		// Get the integer after the underscore of the id string for the current spotlight.
		var spotIDCurr = $("#spotlight_content > div")[0].id.split('_')[1];
		var XMLPath = "/rss/spotlightFetcher.cfm?spotlight=" + (this.className == 'backward' ? spotIDCurr - 1 : Number(spotIDCurr) + 1);
		// alert("Fetching " + XMLPath);
		$.get(XMLPath, {}, XmlOnLoad);
		return false;
	};

	$("#spotlight_controls > a").click(switchSpotlight);
/*
	$("#spotlight_controls > .backward").click(function() {
		var spotIDCurr = ($("#spotlight_content > div")[0].id);
				spotIDCurr = spotIDCurr.substring(10, spotIDCurr.length);
		var spotIDBack = $("#spotlight_controls > .backward")[0].href;
				spotIDBack = spotIDBack.substring(spotIDBack.length-1, spotIDBack.length);	// IE doesn't support [x] style slicing
		var XMLPath = "/rss/spotlightFetcher.cfm?spotlight=" + spotIDBack;
		// alert("Switching from " + spotIDCurr + " to " + spotIDBack + "\nXMLPath = " + XMLPath);
		$.get(XMLPath,{}, XmlOnLoad);
		return false;
	});


	$("#spotlight_controls > .forward").click(function() {
		var spotIDCurr = ($("#spotlight_content > div")[0].id);
				spotIDCurr = spotIDCurr.substring(10,spotIDCurr.length);
		var spotIDNext = $("#spotlight_controls > .forward")[0].href;
				spotIDNext = spotIDNext.substring(spotIDNext.length-1,spotIDNext.length); // IE doesn't support [x] style slicing
		var XMLPath = "/rss/spotlightFetcher.cfm?spotlight=" + spotIDNext;
		// alert("Switching from " + spotIDCurr + " to " + spotIDNext + "\nXMLPath = " + XMLPath);
		$.get(XMLPath,{}, XmlOnLoad);
		return false;
	});
*/
	function XmlOnLoad(xmlData, strStatus) {
		// FIXME: somewhat of a flicker between the remove and the prepend...
		var foo = $(".spotlight").children().not("#spotlight_controls").remove();
		$(".spotlight").prepend($(xmlData).children().not("#spotlight_controls"));
		return false;
	}

});
