var tick_total=0;
var tick_random_total=0;
var last_j;
var j_ramdom;

function ticker(source,destination,time,i){
	i=i==null?0:i;
	var counter=0;
	while(document.getElementById(source+counter)){
		counter++;
	}
	container=document.getElementById(destination);
	if(content=document.getElementById(source+i)){
		container.innerHTML=content.innerHTML;
		i=i<counter-1?i+1:0;
		setTimeout("ticker('"+source+"','"+destination+"',"+time+","+i+")",time);
	}
}
// obsolete if ajax version was finished and all elements updated
function ticker_random(source,destination,time){
	counter=0;
	while(document.getElementById(source+counter)){
		counter++;
	}
	last_j=j_ramdom;
	j_ramdom=Math.floor(Math.random()*counter);
	
	container=document.getElementById(destination);
	content=document.getElementById(source+j_ramdom);
	container.innerHTML=content.innerHTML;
	
	// répète si le meme contenu si non il attend timeout
	if(j_ramdom==last_j){
		ticker_random(source,destination,time);
	}
	else{
		setTimeout("ticker_random('"+source+"','"+destination+"',"+time+")",time);
	}
}

// the ajax version of ticker_random()
function ajax_ticker(containerId, doAjax, hold){
	var data= "doAjax=" + doAjax;
	
	// sending data
	var http = getHTTPObject();
	var container = document.getElementById(containerId);
	var url = '/includes/ajax.php';
	http.open('POST', url , true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
	http.onreadystatechange = function (){
		if(http.readyState == 4){
			container.innerHTML = http.responseText;
			setTimeout("ajax_ticker('" + containerId + "', '" + doAjax + "', '" + hold + "' )", hold);
		}
		else if(http.readyState == 1){
			//container.innerHTML = "... loading";
		}
	}
	http.send(data);
	
	
}
