var rotBlock = new Array();
var len = 0;
var itemIndex = 0;
var fTimerID = null;
var buttonTime = 100;
var rotateTime = 4000;

function rotateInit(){
        //alert( "rotateInit" );
        for (var x=0; x<arguments.length; x++)
		{ rotBlock[x] = arguments[x]; };
        len = (rotBlock.length)-1;
}

function rotate() {
	if (fTimerID != null)
		{ clearTimeout(fTimerID); }

	document.getElementById(rotBlock[itemIndex]).style.display = "none";
//	document.getElementById(rotBlock[itemIndex] + "_sel").style.border = "1px outset #ddd";
	document.getElementById(rotBlock[itemIndex] + "_sel").style.backgroundColor = "#ccc";

	itemIndex++;

// alert("index: " + itemIndex + "len: " + len);

	if(itemIndex > len)
		{ itemIndex = 0; }

	document.getElementById(rotBlock[itemIndex]).style.display = "block";
//	document.getElementById(rotBlock[itemIndex] + "_sel").style.border = "1px inset #ccc";
	document.getElementById(rotBlock[itemIndex] + "_sel").style.backgroundColor = "#ff0";

// alert("In the yellow: " + itemIndex + "Yellow: " + len);

	fTimerID = setTimeout('rotate()', rotateTime);
	return itemIndex;
}

function rotate_to(selection) {
	if (selection != null) {
		if (fTimerID != null)
			{ clearTimeout(fTimerID); }

		document.getElementById(rotBlock[itemIndex]).style.display = "none";
		document.getElementById(rotBlock[itemIndex] + "_sel").style.backgroundColor = "#ccc";

		itemIndex = selection;

		document.getElementById(rotBlock[itemIndex]).style.display = "block";
		document.getElementById(rotBlock[itemIndex] + "_sel").style.backgroundColor = "#ff0";
	}
}
  
function forward() {
	if (fTimerID != null)
		{ clearTimeout(fTimerID); }

	fTimerID = setTimeout('rotate()', buttonTime);
}

function backwards() {
	if (fTimerID != null)
		{ clearTimeout(fTimerID); }

	document.getElementById(rotBlock[itemIndex]).style.display = "none";
	document.getElementById(rotBlock[itemIndex] + "_sel").style.backgroundColor = "#ccc";

	itemIndex--;
	if(itemIndex <= -1)
		{ itemIndex = len; }

	document.getElementById(rotBlock[itemIndex]).style.display = "block";
	document.getElementById(rotBlock[itemIndex] + "_sel").style.backgroundColor = "#ff0";

	fTimerID = setTimeout('rotate()',rotateTime);
	return itemIndex;
}
