var xreq;
var highlightUids = new Array();
var currentIdx = -1;
var moveAlongTimer = null;
function rotatingLoadContent() {
	setFade(0);
	var highlights = document.getElementById("rotatingContent").innerHTML;
//	highlightUids = highlights.split(",");
	var url = "/content/super_content.php?highlights=" + highlights;
	if(window.XMLHttpRequest) {
		xreq = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		xreq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xreq.open("GET", url, true);
	xreq.onreadystatechange = contentcallback;
	xreq.send(null);
}

function contentcallback() {	
	if(xreq.readyState == 4) {
		var response = xreq.responseXML;	
		var resp = response.getElementsByTagName("response");
		highlightUids = (resp[0].getElementsByTagName("highlights")[0].childNodes[0].nodeValue).split(",");

		getObject("rotatingContent").innerHTML = resp[0].getElementsByTagName("content")[0].childNodes[0].nodeValue;
		currentIdx = 0;
		showHighlight(0);
		if (highlightUids.length>0){
			fade(70);
			moveAlongTimer = setTimeout("moveAlong()", 5000);
		}
	}
}
function hideHighlight(idx){
	document.getElementById("hr_" + highlightUids[idx]).style.background = "white";
	document.getElementById("hr_" + highlightUids[idx]).style.borderBottom = "1px dotted #cccccc";
	document.getElementById("cr_" + highlightUids[idx]).style.display = "none";
}
function showHighlight(idx){
	document.getElementById("hr_" + highlightUids[idx]).style.background = "#cccccc";
	document.getElementById("hr_" + highlightUids[idx]).style.borderBottom = "none";

	document.getElementById("cr_" + highlightUids[idx]).style.display = "inline";
}
function moveAlong(){
	var t = fade(20);
	setTimeout('hideHighlight(' + currentIdx + ')', t+5);
	currentIdx++;
	if (currentIdx>=highlightUids.length){
		currentIdx = 0;
	}
	setTimeout('showHighlight(' + currentIdx + ')', t+6);
	setTimeout('fade(' +100 + ')', t+10);

	moveAlongTimer = setTimeout("moveAlong()", 10000);
}
function getObject(obj) {
	var o;
	if(document.getElementById) o = document.getElementById(obj);
	else if(document.all) o = document.all.obj;	
	return o;	
}
function pauseRotation(){
	if (moveAlongTimer != null){
		document.getElementById("hr_controller").innerHTML = "<a href=\"javascript:pauseRotation();\">start</a>";
		clearTimeout(moveAlongTimer);
	} else {
		document.getElementById("hr_controller").innerHTML = "<a href=\"javascript:pauseRotation();\">pause</a>";
		moveAlong();
	}
}
function fade(amt) {
	if(amt <= 100) {
		var t = 0;
		setFade(amt);
		amt += 10;
		setTimeout("fade("+amt+")", 5);
		t += 5;
		return t;
    }
    return 0;
}

function setFade(amt) {
	var obj = getObject("rotatingContent");
	amt = (amt == 100)?99.999:amt;
	obj.style.filter = "alpha(opacity:"+amt+")";
	obj.style.KHTMLOpacity = amt/100;
	obj.style.MozOpacity = amt/100;
	obj.style.opacity = amt/100;
}


function jumpTo() {
	var m = getObject("month");
	var y = getObject("year");
	navigate(m.options[m.selectedIndex].value,y.options[y.selectedIndex].value,'');
	hideJump();
}