indice = new Array();
timer = new Array();
indice['offre'] = -1;
indice['evt'] = -1;
time = 10000;

function callScript(scriptName, i, zone){
	
	var xhr_object = null; 

	if(window.XMLHttpRequest) // Firefox 
		xhr_object = new XMLHttpRequest(); 
	else if(window.ActiveXObject) // Internet Explorer 
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else { // XMLHttpRequest non supporté par le navigateur 
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		return; 
	}
	
	xhr_object.open("GET", scriptName + '?indice=' + i, false);
	xhr_object.setRequestHeader("Content-type", "text/xml");
	xhr_object.send();
	
	if(xhr_object.responseText == ""){
		if(indice[zone] == 1){
			clearInterval(timer[zone]);
			return null;
		}
		reset(zone);
		return null;
	}
	
	$('#bloc_ajax_'+zone).stop(true, true).fadeOut('fast');
	
	$('#bloc_ajax_'+zone).html(xhr_object.responseText);
	
	$('#bloc_ajax_'+zone).stop(true, true).fadeIn('slow');
}

function reset(zone){
	indice[zone] = -1;
	if(zone == 'offre'){
		clearInterval(timer['offre']);
		timer['offre'] = setInterval("start_offre()", time);
	}
	if(zone == 'evt'){
		clearInterval(timer['evt']);
		timer['evt'] = setInterval("start_evt()", time);
	}
}
function start_offre(){
	indice['offre']++;
	callScript('includes/get_next_offre.php', indice['offre'], 'offre');
}
function start_evt(){
	indice['evt']++;
	callScript('includes/get_next_evt.php', indice['evt'], 'evt');
}

$(document).ready(function(){
	start_offre();
	start_evt();
	timer['offre'] = setInterval("start_offre()", time);
	timer['evt'] = setInterval("start_evt()", time);
});

