var valoreId=0;
var counter=0;
var temporizza;

function carosello(divId){
    clearTimeout(temporizza);	
	var x=0;
	cont=document.getElementById('carosello');
	p=cont.getElementsByTagName('p');
	
	img=document.getElementById('img_carosello');
	imgA=img.getElementsByTagName('div');

 	
	for(i=0;i<p.length;i++){

		//p[i].style.background="transparent";
		//img.getElementById('carosello_image_'+i).style.display=none;
		imgA[i].style.display="none";
		span=p[i].getElementsByTagName('span');	
		for(j=0;j<span.length;j++){
			span[j].style.display="none";
			
		}
		
	}
	
	pAperto=document.getElementById('carosello_'+divId);
	aAperto=document.getElementById('carosello_image_'+divId);
	aAperto.style.display="block";
	//pAperto.style.background="transparent";
	spanAperto=pAperto.getElementsByTagName('span');
		for(i=0;i<spanAperto.length;i++){
			spanAperto[i].style.display="block";
		}
		/** posizionamento del div successivo**/	
	if(divId<(p.length-1)){	
		nextDiv=divId+1;
	}else{
		nextDiv=0;
		counter++;
	}
	if(counter>3){
		/** counter=0;**/
		stopTeporizzazione();
	}else{
		temporizzazione(nextDiv);
	}	

	
	return counter;
}

function temporizzazione(valore){
	temporizza=setTimeout('carosello('+valore+');',8000);
}
function stopTeporizzazione(){
if(counter>9){bloc();}
else if(counter<3) {counter=0;}
else {counter=2; }
   

clearTimeout(temporizza);	
}

function bloc(){
		counter=counter+5;
clearTimeout(temporizza);
	if(counter>24){
bloc2();
	}
}

function bloc1(){
		counter=10;
clearTimeout(temporizza);
}

function bloc2(){
		counter=0;
clearTimeout(temporizza);
}
