var rotatesImg = new Array();
var rotatesSteps = new Array();
var rotatesRunned = false;

function runRotationTimeout() {
	rotatesRunned = true;
	var stepsForTransition = 15;
	var stepsForKeep = 15;

	for ( i = 0; i < rotatesImg.length; i++ ) {

		var divs = rotatesImg[i].getElementsByTagName('div');

		var stepPartial = rotatesSteps[i] % (stepsForTransition+stepsForKeep);
		var p1;
		var p2;
		if ( stepPartial < stepsForKeep ) {
			p1 = 100;
		}
		else {
			var stepTrans = stepPartial - stepsForKeep;
			p1 = 100 - (stepTrans / stepsForTransition)*100;
		}
		p2 = 100 - p1;

		var indexImg1 = Math.floor(rotatesSteps[i]/(stepsForTransition+stepsForKeep));
		var indexImg2 = (indexImg1+1)%divs.length;
		var indexImg0 = (indexImg1-1+divs.length)%divs.length;
		
		if ( divs[indexImg0].filters ) {
			divs[indexImg0].filters.alpha.opacity=0;
			divs[indexImg1].filters.alpha.opacity=p1;
			divs[indexImg2].filters.alpha.opacity=p2;
		}
		else if ( divs[indexImg0].style && divs[indexImg0].style.MozOpacity  ) {
			divs[indexImg0].style.MozOpacity = 0;
			divs[indexImg1].style.MozOpacity = p1/100;
			divs[indexImg2].style.MozOpacity = p2/100;
		}

		maxStep = (stepsForTransition+stepsForKeep)*divs.length;
		rotatesSteps[i] = (rotatesSteps[i] + 1)%maxStep;
	}

	setTimeout( runRotationTimeout, 100 );
}

function addRotation(identifiant) {
	rotatesImg[rotatesImg.length] = document.getElementById(identifiant);
	rotatesSteps[rotatesSteps.length] = 0;
}

function runRotation() {
	if ( rotatesRunned == false )
		runRotationTimeout();
}
