var current_page = 1;
var current_image = 0;

function init(menu) {
	var info = new Array();
	info = document.getElementsByClassName("info");
	for(i=0; i < info.length; i++) {
		info[i].style.display = "none";
	}
	
	if(menu) {
		op = menu.split(',');
		for(i=0; i < op.length; i++) {
			menu = 'info'+op[i];
			document.getElementById(menu).style.display = "";
		}
	}
	
	if(document.getElementById("page_1")) {
		var pages = new Array();
		
		pages = document.getElementsByClassName("navigue");
		for(i=0; i < pages.length; i++) {
			pages[i].style.display = "none";
			
		}
		document.getElementById("page_1").style.display = "";
	}
	
	if(document.getElementsByClassName("image")) {
		var imgs = new Array();

		imgs = document.getElementsByClassName("image");
		for(i=0; i < imgs.length; i++) {
			imgs[i].style.filter = "alpha(Opacity=80)";
			imgs[i].style.opacity = 0.8;
			
			imgs[i].onmouseover =  function() {
				opc = 100;
				document.getElementById(this.id).style.filter = "alpha(Opacity="+opc+")";
				document.getElementById(this.id).style.opacity = opc/100;
			};

			imgs[i].onmouseout =  function() {
				opc = 80;
				document.getElementById(this.id).style.filter = "alpha(Opacity="+opc+")";
				document.getElementById(this.id).style.opacity = opc/100;
			};

		}
	}
}

function hide_img(nb) {
	for(i=1; i < nb; i++) {
		if(document.getElementById("image"+i)) { document.getElementById("image"+i).style.display = "none"; }
	}
}

function previous(nb) {
	if(nb != 1) {
		if(current_page != 1) {
			desactive();
			self.setTimeout("active("+nb+")",1000);

			new Effect.Fade(document.getElementById('page_'+current_page));
			new Effect.Appear(document.getElementById('page_'+(current_page-1)));

			current_page--;
		} else {
			desactive();
			self.setTimeout("active("+nb+")",1000);

			new Effect.Fade(document.getElementById('page_'+current_page));
			new Effect.Appear(document.getElementById('page_'+nb));

			current_page = nb;	
		}
	}
}

function next(nb) {
	if(nb != 1) {
		if(current_page != nb) {
			desactive();
			self.setTimeout("active("+nb+")",1000);

			new Effect.Fade(document.getElementById('page_'+current_page));
			new Effect.Appear(document.getElementById('page_'+(current_page+1)));

			current_page++;
		} else {
			desactive();
			self.setTimeout("active("+nb+")",1000);

			new Effect.Fade(document.getElementById('page_'+current_page));
			new Effect.Appear(document.getElementById('page_1'));

			current_page = 1;
		}
	}
}

function active(nb) {
	document.getElementById('previous').innerHTML = '<a href="javascript:previous('+nb+')"><img src="images/left.gif" alt="" /></a>';
	document.getElementById('next').innerHTML = '<a href="javascript:next('+nb+')"><img src="images/right.gif" alt="" /></a>';
}

function desactive() {
	document.getElementById('previous').innerHTML = '<img src="images/left.gif" alt="" />';
	document.getElementById('next').innerHTML = '<img src="images/right.gif" alt="" />';
}

function openmenu(id,e,parent) {
	nom = 'info'+id;
	
	var info = new Array();
	info = document.getElementsByClassName("info");
	if(parent == 0) {
		for(i=0; i < info.length; i++) {
			info[i].style.display = "none";
		}
	}
	
	new Effect.toggle($(nom),'blind');
}

function imgGalerie(image) {
	if(image != current_image) {
		new Effect.BlindUp(document.getElementById('image'+current_image));
		new Effect.BlindDown(document.getElementById('image'+image));
		current_image = image;
		img = document.getElementsByClassName("image");
		for (i=0; i<img.length;i++) {
			img[i].innerHTML = "<img src=\"images/ombre.gif\" alt=\"\" />";
		}
		setTimeout("appear_img()", 1000);
	}
}

function appear_img() {
	img = document.getElementsByClassName("image");
	for (i=0; i<img.length;i++) {
		img[i].innerHTML = '<a href="javascript:imgGalerie('+i+')" title=""><img src="images/ombre.gif" alt="" /></a>';
	}
}

function addToFavorites() {
	if (document.all) { window.external.AddFavorite(location.href, document.title); }
	else { alert('Vous pouvez faire CTRL + D pour ajouter cette page dans vos signets, ou favoris.') }
}

function page(cat) {
	document.getElementById('contenu').style.display = "none";
	ajax(cat);
}

function ajax(cat) {
	new Ajax.Updater('contenu', 'index.php', {onComplete:function(request){show_page()},parameters:'rubid=' + encodeURIComponent(cat), asynchronous:true, evalScripts:true});
}

function show_page() {
	new Effect.Appear(document.getElementById('contenu'));	
}

function hide_page() {
	new Effect.Fade(document.getElementById('contenu'));	
}

function retour() {
	history.go(-1);	
}

function construct() {
	alert("Le choix de la langue n'est pas disponible actuellement / De keus van de taal is momenteel niet beschikbaar");
}

/* code */

function question(value,chron,nb,quizz) {
	if(chron) {
		document.getElementById("chronos").style.display = "block";
	}
	if(value != 1) {
		$precedante = value - 1;
		new Effect.BlindUp(document.getElementById("quest_"+$precedante));
	}
	if(value == 1) {
		appear(value);
	} else {
		self.setTimeout('appear('+value+')',950);
	}
	new Ajax.Updater('boutons', 'code.php', {parameters:'quest=' + encodeURIComponent(value) + '&action=suivante&quizzid=' + quizz, asynchronous:true, evalScripts:true});
	if(chron) {
		if(quest == (nb+1)) {
			document.result.submit();	
		} else {
			chrono(nb);
		}
	}
}

function question_back(value) {
	$precedante = value + 1;
	new Effect.BlindUp(document.getElementById("quest_"+$precedante));

	self.setTimeout('appear('+value+')',950);
	new Ajax.Updater('boutons', 'code.php', {parameters:'quest=' + encodeURIComponent(value) + '&action=suivante', asynchronous:true, evalScripts:true});
}

function appear(value) {
	new Effect.BlindDown(document.getElementById("quest_"+value));
}

function hide(value) {
	new Effect.BlindUp(document.getElementById("quest_"+value));
}

function execute(value,action,idquest) {
	new Ajax.Updater('liste', 'liste.php', {onLoading:function(request){Element.show('save')}, onComplete:function(request){Element.hide('save')},parameters:'value=' + encodeURIComponent(value) + '&action=' + encodeURIComponent(action) + '&idquest=' + encodeURIComponent(idquest), asynchronous:true, evalScripts:true});	
}

function majrep(value,action,idquest,idrep) {
	new Ajax.Updater('liste', 'liste.php', {onLoading:function(request){Element.show('save')}, onComplete:function(request){Element.hide('save')},parameters:'value=' + encodeURIComponent(value) + '&action=' + encodeURIComponent(action) + '&idquest=' + encodeURIComponent(idquest) + '&idrep=' + encodeURIComponent(idrep), asynchronous:true, evalScripts:true});	
}

function majquest(value,action,idq,idquest) {
	new Ajax.Updater('liste', 'liste.php', {onLoading:function(request){Element.show('save')}, onComplete:function(request){Element.hide('save')},parameters:'value=' + encodeURIComponent(value) + '&action=' + encodeURIComponent(action) + '&idquest=' + encodeURIComponent(idquest) + '&idq=' + encodeURIComponent(idq), asynchronous:true, evalScripts:true});	
}

function addimg(id) {
	document.getElementById("img_"+id).style.display = "block";
}

function closeimg(id) {
	document.getElementById("img_"+id).style.display = "none";
}

function config(value,action) {
	new Ajax.Updater('config', 'config.php', {parameters:'value=' + encodeURIComponent(value) + '&action=' + encodeURIComponent(action), asynchronous:true, evalScripts:true});	
}

/* Chrono */

function chrono(nb){
	centi--;
	if (secon==0 && centi==0){rasee(nb)}
	if (centi==0){centi=9;secon--}
	if (secon < 10){pre = "0"} else { pre = ""}
	document.getElementById('centi').innerHTML = " "+centi+"0";
	document.getElementById('sec').innerHTML = pre+secon;
	compte=setTimeout('chrono('+nb+')',100);
}

function rasee(nb){
	question(quest,1,nb);
	clearTimeout(compte);
	quest++;
	centi=9;
	secon=time;
	if (secon < 10){pre = "0"} else { pre = ""}
	document.getElementById('centi').innerHTML = " "+centi+"0";
	document.getElementById('sec').innerHTML = pre+secon;
}
