
var timerID = 0;
var tStart  = null;

var sezioneNews='notFound';
var sezioneFormazione='notFound';
var sezioneTeatri='notFound';
var sezioneVarie='notFound';
var sezioneScuole='notFound';

function ExecuteNews(){
	Reset();
	Start();
	
}

function FindNews(){
	if (document.getElementById('tabnews_news_0')){
		sezioneNews=-1;
	}
	if (document.getElementById('tabnews_formazione_0')){		
		sezioneFormazione=-1;
		
	}
	if (document.getElementById('tabnews_teatri_0')){
		sezioneTeatri=-1;
	}
	if (document.getElementById('tabnews_varie_0')){
		sezioneVarie=-1;
	}
	
	if (document.getElementById('tabnews_scuole_0')){
		sezioneScuole=-1;
	}
	
}



function NewsUpdate(){
	if (sezioneNews!='notFound'){		
		sezioneNews=NewsToogle('news',sezioneNews);
		if (sezioneNews==-1){
			sezioneNews=NewsToogle('news',sezioneNews);
		}
		//alert(sezioneNews);		
	}
	
	if (sezioneFormazione!='notFound'){		
		sezioneFormazione=NewsToogle('formazione',sezioneFormazione);
		if (sezioneFormazione==-1){
			sezioneFormazione=NewsToogle('formazione',sezioneFormazione);
		}
		//alert(sezioneNews);		
	}
	if (sezioneTeatri!='notFound'){		
		sezioneTeatri=NewsToogle('teatri',sezioneTeatri);
		if (sezioneTeatri==-1){
			sezioneTeatri=NewsToogle('teatri',sezioneTeatri);
		}
		//alert(sezioneNews);		
	}
	if (sezioneVarie!='notFound'){		
		sezioneVarie=NewsToogle('varie',sezioneVarie);
		if (sezioneVarie==-1){
			sezioneVarie=NewsToogle('varie',sezioneVarie);
		}
		//alert(sezioneNews);		
	}
	
	if (sezioneScuole!='notFound'){		
		sezioneScuole=NewsToogle('scuole',sezioneScuole);
		if (sezioneScuole==-1){
			sezioneScuole=NewsToogle('scuole',sezioneScuole);
		}
		//alert(sezioneNews);		
	}
}

function NewsToogle(type,countNews){
	countNews++;	
	//alert(countNews);
	var newsId;
	var i;
	for (i=0;i<41;i++){
		newsId='tabnews_'+type+'_'+i;		
		//alert(newsId);
		if (!document.getElementById(newsId)){	
			if (i==countNews){
				countNews=-1;	
			} else {
				
			}
			return countNews;			
		}				
		if (i==countNews){
			//alert ('choose:'+i);
			document.getElementById(newsId).style.display='block';	
		} else {
			document.getElementById(newsId).style.display='none';	
		}		
	}
	
	return countNews;
}


function UpdateTimer() {	
	/*
	try{
		*/
   if(timerID) {
      clearTimeout(timerID);
      clockID  = 0;
   }

   /*
   if(!tStart)

   tStart   = new Date();
   var   tDate = new Date();
   var   tDiff = tDate.getTime() - tStart.getTime();

   tDate.setTime(tDiff);

   document.theTimer.theTime.value = "" 
                                   + tDate.getMinutes() + ":" 
                                   + tDate.getSeconds();
   */
   
   NewsUpdate();
   
   timerID = setTimeout("UpdateTimer()", 3500);
 /* } catch(er){
  	
  }
  */
}

function Start() {
   FindNews();	
	
   tStart   = new Date();

   //document.theTimer.theTime.value = "00:00";

   timerID  = setTimeout("UpdateTimer()", 3500);
}

function Stop() {
   if(timerID) {
      clearTimeout(timerID);
      timerID  = 0;
   }

   tStart = null;
}

function Reset() {
   tStart = null;
 //  document.theTimer.theTime.value = "00:00";
}