
function ajax_req_defilant(){
	//Création d'une requete ajax
	http_defilant = createRequestObject();
	http_defilant.open("POST","modules/defilant/mod_defilant.php",true);
	http_defilant.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	
	http_defilant.onreadystatechange = ajax_ecr_defilant;
	http_defilant.send("");
	
}

//Traitement du retour ajax 
function ajax_ecr_defilant(){
	//On se sert du module de connexion pour le raise en cas d'erreur serveur imap
	if (http_defilant.readyState == 4){
		ajax_load(0);
		if (http_defilant.status == 200){
			//C'est ok : on affiche le module d'defilant
			var doc_defilant = document.getElementById("defilant");
			doc_defilant.innerHTML=http_defilant.responseText;
			made_longueur();
			defile(20,0);
		}
		else {
			affiche_reader("Désolé, serveur occupé...");
		}
	}
	else{ajax_load(1);}
}

actif = window.setTimeout("",130);

function defile(xpos,taille){
	//Repositionnement
	var doc_defilant = document.getElementById("defilant");
	doc_defilant.style.left=xpos+"%";
	//Récupération de la taille sans le %
	if(taille==0){
		made_longueur();
		taille = doc_defilant.style.width;
		var reg = new RegExp("(%)","g");
		taille = taille.replace(reg,"");
		clearTimeout(actif);
	}
	//affiche_reader(xpos+" et taille "+taille);
	//Bord
	if(-xpos>= taille){xpos=20;}
	xpos=xpos-0.5;
	//Suivant
	actif = window.setTimeout("defile("+xpos+","+taille+")",130);
}

function made_longueur(){
	var doc_defilant = document.getElementById("defilant");
	// Pour compter sans les balises
	var compte = 1;
	var i = 0;
	var taille = 0;
	for(i=0;i<=doc_defilant.innerHTML.length;i++){
		if(doc_defilant.innerHTML[i]=="<"){compte=0;}
		if (compte == 1){taille = taille+1;}
		if(doc_defilant.innerHTML[i]==">"){compte=1;}
	}
	
	taille = taille* 6; //Le 12px gras fait 6px de large
	taille = 100*taille/window.innerWidth;
	doc_defilant.style.width=taille+"%";
	//alert(doc_defilant.style.width);

}
