var count = 0;
var speed = 3000;
var active = 0;
var play=true;
var t;


function tournicote(){
	num = count;
	remplacePar(num);
	count ++;
	if(count >= legende.length)count = 0;
	clearTimeout(t);
	t = window.setTimeout('tournicote()',speed);
}

function relance(){
	count=0;
	clearTimeout(t);
	tournicote();
}

function stop(){
	clearTimeout(t);
	if(!play){
		tournicote();
	}
	play=!play;

}

function plusVite(){
	if((speed/2) < 100)alert('humm...');
	else speed = speed / 2;
	tournicote();
}

function moinsVite(){
	if((speed*2) > 20000)alert('humm...');
	else speed = speed * 2;
	tournicote();
}

function remplacePar(idPhoto){
	document.getElementById('retro_une_legende').innerHTML = legende[idPhoto];
	document.getElementById('laBigPhoto').style.visibility = 'hidden';
	document.getElementById('laBigPhoto').src = photo[idPhoto].src;
	//document.getElementById('laBigPhoto').width = width[idPhoto];
	document.getElementById('laBigPhoto').height = height[idPhoto];
	//document.getElementById('laBigPhoto').style.marginTop = (310 - height[idPhoto])/2 + 'px';
	document.getElementById('laBigPhoto').style.visibility = 'visible';
	for(var i=0;i < legende.length; i++){
		document.getElementById('retro_id_' + i).style.border = '1px solid #669900'; 
	}
	document.getElementById('retro_id_' + idPhoto).style.border = '1px solid #ffffff'; 
	
	active = idPhoto;
}

function lance(){
	clearTimeout(t);
}

function click(idPhoto){
	clearTimeout(t);
	play=false;
	count = idPhoto +1;
	if(count >= legende.length)count = 0;
	
	remplacePar(idPhoto);

}

window.onload=tournicote;
