function startRotor(rotorName){
	var totalDivs = 0;
	while (document.getElementById(rotorName + totalDivs)!=null){
		document.getElementById(rotorName).appendChild(document.getElementById(rotorName+totalDivs));
		totalDivs++
	}
	
	document.getElementById(rotorName+"-loading").style.display = "none";
	rotate(rotorName, 0, totalDivs);
}

function rotate(rotorName, index, size){
	if(index == 0){
		lastIndex = size - 1;
	} else {
		lastIndex = index-1;
	}
	 
	rotor = document.getElementById(rotorName); 
	//document.getElementById("gastronomia-garbage").appendChild(document.getElementById(rotorName+lastIndex)); 
	//rotor.appendChild(document.getElementById(rotorName + index));
	fadeIn(rotorName + index);  
	document.getElementById(rotorName + lastIndex).style.display = "none";
	
	var next = index+1;
	if(next == size){ 
		next = 0; 
	}
	 
	setTimeout("rotate('" + rotorName + "', "+ next + ", " + size +")", 5000);
} 

function fadeIn(id){ 
	setVisibility(id, false);
	changeOpac(0, id); 
	setVisibility(id, true);
	opacity(id, 0, 100, 2000);
}

function setVisibility(id, visible){
	if(visible){
		document.getElementById(id).style.display = "block";
	} else{
		document.getElementById(id).style.display = "none";
	}
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
    if(opacEnd == 0){
		setTimeout("setVisibility('"+ id + "', false)", millisec);
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 
