var rotBlock = new Array();
var len = 0;
var itemIndex = 0;
var fTimerID = null;
var buttonTime = 100;
var alternarTime = 7000;

function alternarInit(){
        for (var x=0; x<arguments.length; x++){
            rotBlock[x] = arguments[x];
        }
        len = (rotBlock.length)-1;
}

function alternar(){
    if (fTimerID != null) {
    	// alert(fTimerID);
    	clearTimeout(fTimerID);
    }
    document.getElementById(rotBlock[itemIndex]).style.display = "none";
    document.getElementById(rotBlock[itemIndex] + "_sel").style.backgroundColor = "#ffffff";
    itemIndex++;
    if(itemIndex > len)
        itemIndex = 0;
    document.getElementById(rotBlock[itemIndex]).style.display = "block";
    document.getElementById(rotBlock[itemIndex] + "_sel").style.backgroundColor = "#dddddd";
    fTimerID = setTimeout('alternar()', alternarTime);
    return itemIndex;
}

function alternar_to(selection) {
	if (selection != null) {
		if (fTimerID != null) clearTimeout(fTimerID);
		document.getElementById(rotBlock[itemIndex]).style.display = "none";
	        document.getElementById(rotBlock[itemIndex] + "_sel").style.backgroundColor = "#ffffff";
		itemIndex = selection;
		document.getElementById(rotBlock[itemIndex]).style.display = "block";
       		document.getElementById(rotBlock[itemIndex] + "_sel").style.backgroundColor = "#dddddd";
	}
}
   
function forward() {
    if (fTimerID != null) {
    clearTimeout(fTimerID);
    }
    fTimerID = setTimeout('alternar()', buttonTime);
}


function backwards(){
    if (fTimerID != null) {
    clearTimeout(fTimerID);
    }
    document.getElementById(rotBlock[itemIndex]).style.display = "none";
    document.getElementById(rotBlock[itemIndex] + "_sel").style.backgroundColor = "#ffffff";
    itemIndex--;
    if(itemIndex <= -1)
        itemIndex = len;
    document.getElementById(rotBlock[itemIndex]).style.display = "block";
    document.getElementById(rotBlock[itemIndex] + "_sel").style.backgroundColor = "#dddddd";
    fTimerID = setTimeout('alternar()',alternarTime);
    return itemIndex;
}