// Vars
var isLoad = 0;
var path = "Redims/";
var nbr;
var etat_lect=0;
var numero=0;
var roll = 0;

// Fonctions

function loadImages () {
	if ( isLoad != 1 ) {
		path = document.getElementById("path_img").value;
		// Appel du fichier php
		var param_bidon = new Date(); 
		nbr = getAnswerFromFile('/js/parseImg.php?rep='+path+'&type=1','bidon=23'+param_bidon);
		listing = getAnswerFromFile('/js/parseImg.php?rep='+path+'&num=0','bidon=4'+param_bidon);
		LoadData(listing);
		isLoad=1;
	}

}
function getImg (num) {
	var param_bidon = new Date(); 
	listing = getAnswerFromFile('/js/parseImg.php?rep='+path+'&num='+num,'bidon='+param_bidon);
	LoadData(listing);
}

function LoadData(listing) {
	// listing = num|nom|description
	data = listing.split("|");
	num = data[0];
	nom = data[1];
	desc = data[2];

	document.getElementById("img_visio").src = path + nom;
	document.getElementById("img_desc").innerHTML = desc;
	
}
function suivante() {
	numero = numero + 1;
	if (numero == nbr ) numero = 0;
	getImg(numero);
}
function precedente() {
	
	if (numero <= 0) numero = ( nbr - 1 );
	getImg (numero);
	numero -= 1;
}
function changer() {

	if (numero >= nbr ) numero = 0;
	getImg(numero);
	numero = numero + 1;
	roll=setTimeout("changer()", 4000);
}
function initial() {
	window.clearTimeout(roll);
}
function stop() {
if (etat_lect == 1) {
	initial();
	getImg(0);
	etat_lect =0; 
	document.getElementById("imgStop").src= "/img/media_stop_red.png";
	document.getElementById("imgPlay").src= "/img/media_play.png";
}
}
function play() {
	if (etat_lect == 0) {
		etat_lect =1; 
		changer();
		document.getElementById("imgPlay").src= "/img/media_play_green.png";
		document.getElementById("imgStop").src= "/img/media_stop.png";
	}
	else {
		etat_lect =0; 
		initial();
		document.getElementById("imgPlay").src= "/img/media_pause.png";
	}
}

function getAnswerFromFile(fichier,params)
{
	if (window.XMLHttpRequest)     // Objet de la fenêtre courant
	{
			xhr_object = new XMLHttpRequest();     // Firefox, Safari, ...
	}
	else {
		if (window.ActiveXObject)   // Version Active
		{
			   xhr_object = new ActiveXObject("Microsoft.XMLHTTP");    // Internet Explorer
		}
		else {
			alert("ERREUR !");
			return false;
		}
	}
	     
	 xhr_object.open("GET", fichier, false);
	 
	 if ( params == '' )
     	xhr_object.send(null);
	 else
	 	xhr_object.send(params);
		
     if(xhr_object.readyState == 4) return(xhr_object.responseText);
     else return(false);
}
