var rotBlock = new Array();
var rotBlock1 = new Array();
var axlen = 0;
var axlen1 = 0;
var itemIndex = 0;
var itemIndex1 = 0;
var fTimerID = null;
var fTimerID1 = null;

var buttonTime = 100;
var rotateTime = 8000;

function rotateInit(){
        for (var x=0; x<arguments.length; x++){
            rotBlock[x] = arguments[x];
        }
        axlen = (rotBlock.length)-1;
    }

function rotate(){
    if (fTimerID != null) {
    	clearTimeout(fTimerID);
    }
    document.getElementById(rotBlock[itemIndex]).style.display = "none";
    document.getElementById(rotBlock[itemIndex] + "_sel").style.backgroundColor = "#e6e7e8";
    itemIndex++;
    if(itemIndex > axlen)
        itemIndex = 0;
    document.getElementById(rotBlock[itemIndex]).style.display = "block";
    document.getElementById(rotBlock[itemIndex] + "_sel").style.backgroundColor = "#ffffff";
    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 = "#e6e7e8";
		itemIndex = selection;
		document.getElementById(rotBlock[itemIndex]).style.display = "block";
       		document.getElementById(rotBlock[itemIndex] + "_sel").style.backgroundColor = "#ffffff";
	}
}

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 = "#e6e7e8";
    itemIndex--;
    if(itemIndex <= -1)
        itemIndex = axlen;
    document.getElementById(rotBlock[itemIndex]).style.display = "block";
    document.getElementById(rotBlock[itemIndex] + "_sel").style.backgroundColor = "#ffffff";
    fTimerID = setTimeout('rotate()',rotateTime);
    return itemIndex;
}

