function navigation(debut,uid){
	var XHR = null;	
	if(window.XMLHttpRequest) // Firefox
		XHR = new XMLHttpRequest();
	else if(window.ActiveXObject) // Internet Explorer
		XHR = new ActiveXObject("Microsoft.XMLHTTP");
	else { // XMLHttpRequest non supporté par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		return;
	}
	var url = "navigation_AJAX.php";
	var params = "debut="+debut+"&uid="+uid;
		// envoie de la requête, methode GET et de l'url
	XHR .open("GET", url+"?"+params, true);
		// on guette les changements d'état de l'objet
	XHR.onreadystatechange = function attente() {
		// l'état est à 4, requête reçu !
	if(XHR.readyState == 4)     {
		// ecriture de la réponse
	document.getElementById(uid).innerHTML = XHR.responseText;
   	}
	}
	XHR.send(null);		// le travail est terminé
	return;
}

function redimensionnerDiv(id1,id2){
	elementa = document.getElementById(id1);
	elementb = document.getElementById(id2);
	hauteura = elementa.offsetHeight;
	hauteurb = elementb.offsetHeight;
	if(hauteura>hauteurb){
		elementb.style.height = hauteura+'px';
	}
	else{
		elementa.style.height = hauteurb+'px';
	}	
}

/*window.onload = function()
{
		blocs = document.getElementById('indices').value;
		tab_blocs = blocs.split("/");
		for(i=0;i<tab_blocs.length;i++){
			str = tab_blocs[i];
			favoris_indices = str.split("-");
			redimensionnerDiv(favoris_indices[0],favoris_indices[1]);
		}

}*/

function menu_top_action(id,choix){	
	if(choix==1){	couleur='#993399';
		bordure='#660066';
		document.getElementById(id+'_h').style.color = 'white';
	}
	else{
		couleur='#FFCC33';
		bordure='#FF9900';
		document.getElementById(id+'_h').style.color = 'black';
	}
		document.getElementById(id+'_gauche').style.backgroundColor= couleur;
		document.getElementById(id+'_bas2').style.backgroundColor= couleur;
		document.getElementById(id+'_bas3').style.backgroundColor= couleur;
		document.getElementById(id+'_bas4').style.backgroundColor= couleur;
		document.getElementById(id+'_bas1').style.borderColor= bordure;
		document.getElementById(id+'_bas2').style.borderColor= bordure;
		document.getElementById(id+'_bas3').style.borderColor= bordure;
		document.getElementById(id+'_bas4').style.borderColor= bordure;
		document.getElementById(id+'_gauche').style.borderColor= bordure;
		document.getElementById(id+'_haut2').style.backgroundColor= couleur;
		document.getElementById(id+'_haut3').style.backgroundColor= couleur;
		document.getElementById(id+'_haut4').style.backgroundColor= couleur;
		document.getElementById(id+'_haut1').style.borderColor= bordure;
		document.getElementById(id+'_haut2').style.borderColor= bordure;
		document.getElementById(id+'_haut3').style.borderColor= bordure;
		document.getElementById(id+'_haut4').style.borderColor= bordure;

}

function initialise(nomDiv,nomBouton,id,entete,txt,taille){	
	
	if(verifierDiv("input_"+nomDiv+id)==1){	
		document.getElementById(entete).innerHTML = "";
		if(txt.split("_")!=null){
			mots=txt.split("_");
			for(i=0;i<mots.length;i++)
				document.getElementById(entete).innerHTML = document.getElementById(entete).innerHTML +mots[i]+ ' ';			
		}
		else
			mots= txt;
		verifierCouleurs("click",nomDiv,nomBouton,id,taille);
		img1 = document.getElementById(nomDiv+id);
		nom = rechercheAffiche(nomDiv,taille);
		img2 = document.getElementById(nom);
		img2.style.left = 0;
		img2.style.top = 0;
		gauche = img2.offsetLeft+img2.clientWidth;
		haut = img2.offsetTop;
		img1.style.display = "block";
		img1.style.left = gauche;
		img1.style.top= haut;
		remplacer(nomDiv,nomDiv+id,nom,1,taille);
	}
			
}
		
function rechercheAffiche(div,taille){
	bool=0;
	i=1;
	
	while(i<taille && bool==0){
		nom = div+i;
		if(document.getElementById(nom).style.display=="block"){	
			bool=1;
			return nom;	
		}
		else 
			i=i+1;
	}	
}	
		 
function verifierDiv(div){
	if(document.getElementById(div).value == "o")
		return 0;
	else
		return 1;
}

function remplacer(nom,image1,image2,bool,taille){	
    pas=30;
	img1 = document.getElementById(image1);
	img2 = document.getElementById(image2);
	if(image1!=image2){	
	if(bool==1){
			img1.style.left= img2.offsetLeft+img2.clientWidth-10;
			img2.style.left= img2.offsetLeft-pas;
			func = "if(img1.offsetLeft>0)remplacer(\""+nom+"\",\""+image1+"\",\""+image2+"\",1,"+taille+"); else remplacer(\""+nom+"\",\""+image1+"\",\""+image2+"\",0,"+taille+");";		
			setTimeout(func,1);
		}
		else
		{	
			img1.style.left = 0;
			img2.style.display="none";
			img2.style.left = img1.offsetLeft;
			img2.style.top = img1.offsetTop;
		}
			
	}
}

function chargement(bool,mode,nomDiv,nomBouton,entete,taille,textes,temps,indice,nomPlayer){	
	
	txt=textes.toString().split(','); 
	if(bool==1)
	{	
		temps=temps+1;
	}
	else
	{
		if(mode>10)
		{	
			mode=10;	
		}
		if(nomPlayer=="player")
		{	temps=1;
			clearTimeout(timerplayer);
		}
		if(nomPlayer=="miniplayer")
		{	temps=1;
			clearTimeout(timerminiplayer);
		}
		
		i=1;
		verif=0;
 		while(i<taille && verif==0){	
			if(document.getElementById(nomDiv+i).style.display == "block"){
				verif=1;
				if(i==taille-1)
					initialise(nomDiv,nomBouton,1,entete,txt[indice],taille);
				else
					initialise(nomDiv,nomBouton,(i+1),entete,txt[indice+i],taille);
			}
			i=i+1;
		}
		
	}
		

		func = "if("+temps+"<"+mode+")chargement(1,"+mode+",\""+nomDiv+"\",\""+nomBouton+"\",\""+entete+"\","+taille+",\""+textes+"\","+temps+","+indice+",\""+nomPlayer+"\");else chargement(0,"+mode+",\""+nomDiv+"\",\""+nomBouton+"\",\""+entete+"\","+taille+",\""+textes+"\","+temps+","+indice+",\""+nomPlayer+"\");";

		if(nomPlayer=="player")
			timerplayer = setTimeout(func,1000);
		if(nomPlayer=="miniplayer")
			timerminiplayer = setTimeout(func,1000);	
	
}


function verifierCouleurs(action,nomDiv,nomBouton,id,taille){	

	bool=0;
	i=1;

	while(i<=taille-1 && bool==0){
		if(document.getElementById("input_"+nomDiv+i).value=="o")
		{	
			bool=1;			
		}
		else 
			i=i+1;	
	}	

	if(action=="over"){
		if(bool==1&&i!=id)
			document.getElementById(nomBouton+id).style.backgroundColor = "#cfcfcf";			
		if(bool==0)
		{
			document.getElementById(nomBouton+id).style.backgroundColor = "#cfcfcf";		
		}
	}
	
	if(action=="out"){
		if(bool==1&&i!=id)
			document.getElementById(nomBouton+id).style.backgroundColor = "#f7f7f7";			
		if(bool==0)
		{	document.getElementById(nomBouton+id).style.backgroundColor = "#f7f7f7";				
		}
	}
	
	if(action=="click"){
		if(bool==0){	
			document.getElementById("input_"+nomDiv+id).value = "o";
			//document.getElementById(nomBouton+id).style.backgroundColor = "#cfcfcf";
			document.getElementById("input_"+nomDiv+i).value = "n";
			//document.getElementById(nomBouton+i).style.backgroundColor = "#f7f7f7";
		}
		if(bool==1 && id!=i){
			document.getElementById("input_"+nomDiv+i).value = "n";
			//document.getElementById(nomBouton+i).style.backgroundColor = "#f7f7f7";
			document.getElementById("input_"+nomDiv+id).value = "o";
			//document.getElementById(nomBouton+id).style.backgroundColor = "#cfcfcf";
			
		}
		

	}	

}

var passage = 0;
function aggrandissement()
{
	if(passage==0)
	{	passage=1;
		for(i=1;i<=5;i++)
		{	id = "layer"+i;
			document.getElementById(id).style.left = document.getElementById(id).offsetLeft-document.getElementById(id).clientWidth+20;
			document.getElementById(id).style.paddingLeft = document.getElementById(id).clientWidth-10;
			document.getElementById(id).style.paddingRight = document.getElementById(id).style.paddingLeft;
		}
	}
}

var Timer;
var Pas = -1; // vitesse défilement texte

function moveLayer(id,bool,id2) {
	
	Objet = document.getElementById(id);
	Bouton = document.getElementById(id2);
	taille1 = -(Objet.clientWidth/3-Bouton.clientWidth);
	taille2 = -2*(Objet.clientWidth)/3;

	if(taille1<0)
	{	
		if(bool==1){
 			Objet.style.left = Objet.offsetLeft + Pas;
			func = "if(Objet.offsetLeft > taille2 ) moveLayer(\""+ id +"\",1,\""+ id2 +"\"); else moveLayer(\""+ id +"\",0,\""+ id2 +"\");";		
			Timer = setTimeout(func,50);
		}
		else{	
			Objet.style.left =  0;
			func = "moveLayer(\""+ id +"\",1,\""+ id2 +"\");";		
			Timer = setTimeout(func,50);
			
		}
	}

}

var Timer2;
function deplacer(sens,div) {
	pas=10*sens;
	Objet = document.getElementById(div);
	taille= -(Objet.clientWidth - 560)-6;
	if(Objet.offsetLeft<taille)
		Objet.style.left = taille;
	if(Objet.offsetLeft>0)
		Objet.style.left = 0;
	
	if(Objet.offsetLeft<=0 && Objet.offsetLeft>=taille){
		if(sens==1 && Objet.offsetLeft!=0 || sens==-1 && Objet.offsetLeft!=taille)
			Objet.style.left = Objet.offsetLeft + pas;
		func = "if(Objet.offsetLeft<=0 && Objet.offsetLeft>=taille)deplacer("+sens+",\""+div+"\");else clearTimeout(Timer2);";		
		Timer2 = setTimeout(func,1);
	}


}

function fiches_AJAX(mode)
{
	var XHR = null;	
	if(window.XMLHttpRequest) // Firefox
		XHR = new XMLHttpRequest();
	else if(window.ActiveXObject) // Internet Explorer
		XHR = new ActiveXObject("Microsoft.XMLHTTP");
	else { // XMLHttpRequest non supporté par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		return;
	}
	var url = "fiches_AJAX_jdp.php";
	var params = "mode="+mode;
		// envoie de la requête, methode GET et de l'url
	XHR .open("GET", url+"?"+params, true);
		// on guette les changements d'état de l'objet
	XHR.onreadystatechange = function attente() {
		// l'état est à 4, requête reçu !
	if(XHR.readyState == 4)     {
		// ecriture de la réponse
	document.getElementById("haut_derouleur").innerHTML = XHR.responseText;
   	}
	}
	XHR.send(null);		// le travail est terminé
	return;
}

