var Left = -50;
var id;
var Vitesse = 1;
var Url = '#';

function ChangeArrow(ID, idArrow) {
Left = parseInt(document.getElementById(idArrow).style.left.replace('px', ''));
if (document.getElementById(idArrow).style.display == 'none') document.getElementById(idArrow).style.display = 'block';

switch (ID) {
case 'button_1':Url = '/?page=home';break;
case 'button_2':Url = '/?page=search';break;
case 'button_3':Url = '/?page=tests';break;
case 'button_4':Url = '/?page=news';break;
}

document.getElementById('menuCurrentUrl').href=Url;

if (id) clearTimeout(id);
Mouvement = true;

Pixels = document.getElementById(ID).offsetLeft - 7;

if (Left < Pixels) ChangeArrowDirection(Pixels, 2, idArrow);
else ChangeArrowDirection(Pixels, 1, idArrow);

}

//////////////
function ChangeArrowSimple(ID, idArrow) {
Left = parseInt(document.getElementById(idArrow).style.left.replace('px', ''));
if (document.getElementById(idArrow).style.display == 'none') document.getElementById(idArrow).style.display = 'block';

if (id) clearTimeout(id);
Mouvement = true;

Pixels = document.getElementById(ID).offsetLeft + (document.getElementById(ID).offsetWidth / 2);

if (Left < Pixels) ChangeArrowDirection(Pixels, 2, idArrow);
else ChangeArrowDirection(Pixels, 1, idArrow);

}

function ChangeArrowDirection(Pixels, Direction, idArrow) {
Left = parseInt(document.getElementById(idArrow).style.left.replace('px', ''));
var Dif = Pixels - Left;
if (Dif < 0) Dif*=-1;

Vitesse = Math.round(Dif / 10);

if (Direction == 2) Left += Vitesse;
else Left -= Vitesse;

if (Dif < 5) { Left = Pixels; clearTimeout(id); }

document.getElementById(idArrow).style.left = Left+'px';

if (Left >= Pixels && Direction == 1) id = setTimeout("ChangeArrowDirection("+Pixels+", "+Direction+", '"+idArrow+"')", 10);
else if (Left <= Pixels && Direction == 2) id = setTimeout("ChangeArrowDirection("+Pixels+", "+Direction+", '"+idArrow+"')", 10);
}

function toggleTimeChoice(form) {
var checked = document.getElementById('box_'+form).checked;
if (checked) {	$('#'+form+'_time_choice').show(200); }
else {			$('#'+form+'_time_choice').hide(200); }
}

// Ajax

function createRequest() {
	var ajaxRequest = null;
	if(window.XMLHttpRequest) // Moteur Gecko
		ajaxRequest = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE...Fucking Crosoft'.
		ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
	
	return ajaxRequest;
}

function ajaxReturn(divload, page, method, variables, callback) {

var ajaxRequest = createRequest();
var load = false;

if (divload) document.getElementById(divload).innerHTML = '<div align="center"><img src="styles/icons/loaders/loading.gif" alt="" /></div>';

ajaxRequest.Charset = "ISO8859-1";

ajaxRequest.open(method, page, true);

if (method == 'POST') {
ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1"); 
ajaxRequest.send(variables);
}

else { ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1"); ajaxRequest.send(null); }

	ajaxRequest.onreadystatechange = function() {
		if (divload) {
		if(ajaxRequest.readyState < 4 && !load && divload) { document.getElementById(divload).innerHTML = '<div align="center"><img src="styles/icons/loaders/loading.gif" alt="" /></div>'; load = true; }
		}
	
		if(ajaxRequest.readyState == 4) { load = false;
			if (divload) document.getElementById(divload).innerHTML = '';
			if (callback) callback(ajaxRequest.responseText);
		}
	}

}

function countDown(divId, cibleTime, daysEnabled, displayText) {
var test = 'lol';
var date = new Date(); time = Math.floor(date.getTime() / 1000);
resteTime = cibleTime - time;

if (daysEnabled) {
var Jours  = Math.floor(resteTime / (3600 * 24));
var Heures = Math.floor((resteTime - (Jours * 3600 * 24)) / 3600);
}

else {
var Jours = 0;
var Heures = Math.floor(resteTime / 3600);
}

var reste = resteTime - (Heures * 3600) - (Jours * 3600 * 24);
var Minutes = Math.floor(reste / 60);
var Secondes = reste - (Minutes * 60);

if (Secondes == 0 && Minutes == 0 && Heures == 0 && Jours == 0) document.getElementById(divId).innerHTML = 'Terminé.';

else {

	Secondes--;
if (Secondes < 0) { Secondes = 59; Minutes--; } else if (Secondes < 10) { Secondes = '0'+Secondes; }
if (Minutes < 0) { Minutes = 59; Heures--; } else if (Minutes < 10) { Minutes = '0'+Minutes; }
if (daysEnabled) { if (Heures < 0) { Heures = 23; Jours--; } else if (Heures < 10) { Heures = '0'+Heures; } }

if (!displayText) {
if (daysEnabled) texte = Jours+'<sup>Jours</sup>:'+Heures+':'+Minutes+':'+Secondes;
else texte = Heures+':'+Minutes+':'+Secondes;
}

else {
texte = displayText.replace('$jours', Jours);
texte = texte.replace('$heures', Heures);
texte = texte.replace('$minutes', Minutes);
texte = texte.replace('$secondes', Secondes);
}

document.getElementById(divId).innerHTML = texte;
setTimeout('countDown(\''+divId+'\', '+cibleTime+', '+daysEnabled+', \''+displayText+'\')', 1000);
}

}

function seeTest(id) {
$('#dizContent').fadeOut(100, function() { $('#big_body').fadeIn(100) });
ajaxReturn(false, 'pages/ajax/testReturn.php?id='+id, 'GET', false, function(data) {
$('#bigBodyReturn').html(data);
});
}

function displayFiche(id) {
$('#dizContent').fadeOut(100, function() { $('#big_body').fadeIn(100) });
ajaxReturn(false, 'pages/ajax/bigBodyReturn.php?id='+id, 'GET', false, function(data) {
$('#bigBodyReturn').html(data);
});
}

function givePouce(id, note) {
ajaxReturn(false, 'pages/ajax/givePouce.php?id='+id+'&note='+note, 'GET', false, function(data) {
$('#givePouceReturn'+id).fadeOut(100).html(data).fadeIn(100);
});
}
