/* FRONT OFFICE */
var NbreVideoREF = 5;


/* VIDEO */
function retourVideo(){
	if(xmlHttpRequestVideo.readyState==4 || xmlHttpRequestVideo.readyState=="complete") {
		
		//////////////////////////
		// STOP VIDEO ////////////
		for(i=0;i<5;i++){
			if(document.getElementById("playerVideo"+i)){
				document.getElementById("playerVideo"+i).innerHTML='';
			}
		}
		//////////////////////////
		tmpReturn = xmlHttpRequestVideo.responseText.split("___");

		for(i=0;i<NbreVideoREF;i++){
			if(document.getElementById("video"+i+"_"+tmpReturn[0])){
				document.getElementById("video"+i+"_"+tmpReturn[0]).className = "video"+i;
			}
		}
		
		document.getElementById("video"+tmpReturn[2]+"_"+tmpReturn[0]).className = "video"+tmpReturn[2]+"on";
		
		var sa = new SWFObject('site/swf/player.swf','mpl','300','240','9',"#000000");
		sa.addParam("allowfullscreen","true");
		sa.addParam("allowscriptaccess","always");
		sa.addParam("seamlesstabbing","true");
		sa.addParam("flashvars",tmpReturn[3]);
		sa.write('playerVideo'+tmpReturn[0]);

	}
}
function lireVideo(TypeRef,IdRef,IdVideo){
	var pageUrl="site/ajax/lireVideo.php";
		
	if(typeof ActiveXObject == 'undefined') // FIREFOX
	{
		xmlHttpRequestVideo = new XMLHttpRequest();
		xmlHttpRequestVideo.onload = retourVideo;
	}
	else // IE
	{
		xmlHttpRequestVideo = new ActiveXObject("Microsoft.XMLHTTP");
		xmlHttpRequestVideo.onreadystatechange = retourVideo;
	}

	xmlHttpRequestVideo.open("POST", pageUrl, true);
	xmlHttpRequestVideo.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	
	
	dataVideo = "&TypeRef="+TypeRef+"&IdRef="+IdRef+"&IdVideo="+IdVideo;

	xmlHttpRequestVideo.send(dataVideo);
}
function retourRef(){
	if(xmlHttpRequestRef.readyState==4 || xmlHttpRequestRef.readyState=="complete") {
		tmpReturn = xmlHttpRequestRef.responseText.split("___");
		
		document.getElementById("listeVideo"+tmpReturn[0]).innerHTML = tmpReturn[2];
		document.getElementById("enteteVideo"+tmpReturn[0]).innerHTML = tmpReturn[3];
		document.getElementById("texteVideo"+tmpReturn[0]).innerHTML = tmpReturn[4];
		
		tmp = '		document.getElementById("texteVideo'+tmpReturn[0]+'").style.top = "0px";';
		tmp += '	maxHauteur'+tmpReturn[0]+' = -document.getElementById("texteVideo'+tmpReturn[0]+'").offsetHeight+document.getElementById("globalTexteVideo'+tmpReturn[0]+'").offsetHeight;';
		
		tmp += '	var tailleMoveSlide=1100;';
		tmp += '	var vitesseSlide="slow";';
		tmp += '	var pos'+tmpReturn[0]+' = 0;';
		tmp += '	var posPlus'+tmpReturn[0]+' = 50;';
		
		tmp += '	$(".btScrollTop'+tmpReturn[0]+'").click(function(){';
		tmp += '		if(document.getElementById("texteVideo'+tmpReturn[0]+'").offsetHeight > document.getElementById("globalTexteVideo'+tmpReturn[0]+'").offsetHeight) {';
		tmp += '			var tmp = document.getElementById("texteVideo'+tmpReturn[0]+'").style.top;';
		tmp += '			var pos'+tmpReturn[0]+' = Number(tmp.substr(0,(tmp.length-2)));';
		
		tmp += '			if((pos'+tmpReturn[0]+' + posPlus'+tmpReturn[0]+')>0){';
		tmp += '				pos'+tmpReturn[0]+' = 0;';
		tmp += '			} else {';
		tmp += '				pos'+tmpReturn[0]+' += posPlus'+tmpReturn[0]+';';
		tmp += '			}';
		
		tmp += '			$("#texteVideo'+tmpReturn[0]+'")';
		tmp += '			.animate({top: pos'+tmpReturn[0]+'}, vitesseSlide);';
		tmp += '		}';
		tmp += '		return false;';

		tmp += '	});';
		
		tmp += '	$(".btScrollDown'+tmpReturn[0]+'").click(function(){';
		tmp += '		if(document.getElementById("texteVideo'+tmpReturn[0]+'").offsetHeight > document.getElementById("globalTexteVideo'+tmpReturn[0]+'").offsetHeight) {';
		tmp += '			var tmp = document.getElementById("texteVideo'+tmpReturn[0]+'").style.top;';
		tmp += '			var pos'+tmpReturn[0]+' = Number(tmp.substr(0,(tmp.length-2)));';

		tmp += '			if((pos'+tmpReturn[0]+' - posPlus'+tmpReturn[0]+')<maxHauteur'+tmpReturn[0]+'){';
		tmp += '				pos'+tmpReturn[0]+' = maxHauteur'+tmpReturn[0]+';	';
		tmp += '			} else {';
		tmp += '				pos'+tmpReturn[0]+' -= posPlus'+tmpReturn[0]+';';
		tmp += '			}';
		
		tmp += '			$("#texteVideo'+tmpReturn[0]+'")';
		tmp += '			.animate({top: pos'+tmpReturn[0]+'}, vitesseSlide);';
		tmp += '		}';
		tmp += '		return false;';

		tmp += '	});';
		

		lireVideo(tmpReturn[0],tmpReturn[1],'0');
		
		eval (tmp);
	
	}
}

function changeRef(TypeRef,IdRef) {
	var pageUrl="site/ajax/affichRef.php";
		
	if(typeof ActiveXObject == 'undefined') // FIREFOX
	{
		xmlHttpRequestRef = new XMLHttpRequest();
		xmlHttpRequestRef.onload = retourRef;
	}
	else // IE
	{
		xmlHttpRequestRef = new ActiveXObject("Microsoft.XMLHTTP");
		xmlHttpRequestRef.onreadystatechange = retourRef;
	}

	xmlHttpRequestRef.open("POST", pageUrl, true);
	xmlHttpRequestRef.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	
	dataRef = "&TypeRef="+TypeRef+"&IdRef="+IdRef;

	xmlHttpRequestRef.send(dataRef);
}

/* CONTACT */
function retourContact (){
	if(xmlHttpRequestContact.readyState==4 || xmlHttpRequestContact.readyState=="complete") {
		document.getElementById("contenu_5_attente").style.display = 'none';
		document.getElementById("contenu_5_retour").style.display = 'block';
		document.getElementById("erreur").innerHTML = '&nbsp;';
	}
}
function envoiContact(){
	
	
	
	document.getElementById("contenu_5_form").style.display = 'none';
	document.getElementById("contenu_5_attente").style.display = 'block';
	
	var dataContact = "";
	var erreur = 0;
	
	if(document.getElementById("Nom").value!=""){
		dataContact += "&Nom="+document.getElementById("Nom").value;
	} else { erreur = 1; }
	if(document.getElementById("Prenom").value!=""){
		dataContact += "&Prenom="+document.getElementById("Prenom").value;
	} else { erreur = 1; }
	if(document.getElementById("Tel").value!=""){
		dataContact += "&Tel="+document.getElementById("Tel").value;
	} else { erreur = 1; }
	if(document.getElementById("Message").value!=""){
		dataContact += "&Message="+document.getElementById("Message").value;
	} else { erreur = 1; }
	
	if(erreur == 1){
		
		document.getElementById("contenu_5_attente").style.display = 'none';
		document.getElementById("contenu_5_form").style.display = 'block';	
		document.getElementById("erreur").innerHTML = 'Au moins un champ n\'a pas été rempli.';
	} else {
	
		var pageUrl="site/ajax/envoiContact.php";
		
		if(typeof ActiveXObject == 'undefined') // FIREFOX
		{
			xmlHttpRequestContact = new XMLHttpRequest();
			xmlHttpRequestContact.onload = retourContact;
		}
		else // IE
		{
			xmlHttpRequestContact = new ActiveXObject("Microsoft.XMLHTTP");
			xmlHttpRequestContact.onreadystatechange = retourContact;
		}
		
		xmlHttpRequestContact.open("POST", pageUrl, true);
		xmlHttpRequestContact.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		
		//alert(dataContact);
		xmlHttpRequestContact.send(dataContact);
	}

}

/* CONTENT */
function writeContent(str){
	if(xmlHttpRequest.readyState==4 || xmlHttpRequest.readyState=="complete") {  
		
		tmpRetourContent = xmlHttpRequest.responseText.split("@#@#@#@");
		document.getElementById("slidebox").innerHTML = tmpRetourContent[0];
		
		$(document).ready(function(){

			var tailleMoveSlide=1100;
			var vitesseSlide='slow';
			
			// ON VERIFIE COMBIEN DE SLIDE POSSIBLE
			var n = 0;
			var nom = Niveau1Display;
			if(Niveau3Display != '' && Niveau1Display != 2){
				nom = nom + '_' + Niveau2Display;
			}

			for(j=0;j<12;j++){
				if(document.getElementById('left_'+nom+'_'+j)){
					n = j;
				} else {
					break;
				}
			}
			
			if(n>0){
				for(j=0;j<12;j++){
					
					tmpEval = '$(".left_'+j+'").click(function(){';
					tmpEval = tmpEval + '$("#slidebox")';
					if(j==0){
						tmpEval = tmpEval + '.animate({right: tailleMoveSlide*'+n+'}, vitesseSlide);';
					} else {
						tmpEval = tmpEval + '.animate({right: tailleMoveSlide*'+(j-1)+'}, vitesseSlide);';
					}
					tmpEval = tmpEval + 'return false;';
					tmpEval = tmpEval + '});';
					
					eval(tmpEval);
					
					tmpEval = '$(".right_'+j+'").click(function(){';
					tmpEval = tmpEval + '$("#slidebox")';
					if(j==n){
						tmpEval = tmpEval + '.animate({right: tailleMoveSlide*'+0+'}, vitesseSlide);';
					} else {
						tmpEval = tmpEval + '.animate({right: tailleMoveSlide*'+(j+1)+'}, vitesseSlide);';
					}
					tmpEval = tmpEval + 'return false;';
					tmpEval = tmpEval + '});';
					
					eval(tmpEval);
					
				}

				if(Niveau1Display == 2){
					if(Niveau2Display == 0) {
						goN = 0;
					} else if(Niveau2Display == 1) {
						goN = 3;
					} else if(Niveau2Display == 2) {
						goN = 6;
					} else if(Niveau2Display == 3) {
						goN = 7;
					} else if(Niveau2Display == 4) {
						goN = 9;
					} else if(Niveau2Display == 5) {
						goN = 11;
					} else if(Niveau2Display == 6) {
						goN = 11;
					}
				} else {
					goN = Niveau2Display;
				}
				tmpEval = '$("#slidebox")';
				tmpEval = tmpEval + '.animate({right: tailleMoveSlide*'+goN+'}, vitesseSlide);';
				eval(tmpEval);

				// SI REFERENCES
				if(Niveau1Display == 4){

					for(i=0;i<5;i++){
						tmp = '		var posPlus'+i+' = 50;';
						tmp += '	var maxHauteur'+i+' = -document.getElementById("texteVideo'+i+'").offsetHeight+document.getElementById("globalTexteVideo'+i+'").offsetHeight;';
						tmp += '	if(document.getElementById("texteVideo'+i+'").offsetHeight > document.getElementById("globalTexteVideo'+i+'").offsetHeight) {';
						tmp += '		$(".btScrollTop'+i+'").click(function(){';
						tmp += '			var tmp = document.getElementById("texteVideo'+i+'").style.top;';
						tmp += '			var pos'+i+' = Number(tmp.substr(0,(tmp.length-2)));';
						
						tmp += '			if((pos'+i+' + posPlus'+i+')>0){';
						tmp += '				pos'+i+' = 0;';
						tmp += '			} else {';
						tmp += '				pos'+i+' += posPlus'+i+';';
						tmp += '			}';
						
						tmp += '			$("#texteVideo'+i+'")';
						tmp += '			.animate({top: pos'+i+'}, vitesseSlide);';
						tmp += '			return false;';

						tmp += '		});';
						
						tmp += '		$(".btScrollDown'+i+'").click(function(){';

						tmp += '			var tmp = document.getElementById("texteVideo'+i+'").style.top;';
						tmp += '			var pos'+i+' = Number(tmp.substr(0,(tmp.length-2)));';

						tmp += '			if((pos'+i+' - posPlus'+i+')<maxHauteur'+i+'){';
						tmp += '				pos'+i+' = maxHauteur'+i+';	';
						tmp += '			} else {';
						tmp += '				pos'+i+' -= posPlus'+i+';';
						tmp += '			}';
						
						tmp += '			$("#texteVideo'+i+'")';
						tmp += '			.animate({top: pos'+i+'}, vitesseSlide);';
						tmp += '			return false;';

						tmp += '		});';
						
						tmp += '	}';
						
						eval (tmp);
												
					}
					
					// LANCER VIDEO PAR DEFAUT
					lireVideo(Niveau2Display,tmpRetourContent[1],'0');
					
				}
				
			}
			
			if(Niveau1Display == 0){
					var posNews = 0;
					var posPlusNews = 50;
					var vitesseSlideNews = 'slow';
					
					tmp = '		var maxHauteurNews = -document.getElementById("listeNews").offsetHeight+document.getElementById("listeNewsParent").offsetHeight;';
					tmp += '	if(maxHauteurNews<0){';
					tmp += '	$(".btScrollTopNews").click(function(){';
					
					tmp += '		if((posNews + posPlusNews)>0){';
					tmp += '			posNews = 0;	';
					tmp += '		} else {';
					tmp += '			posNews += posPlusNews;';
					tmp += '		}';
					
					tmp += '		$("#listeNews")';
					tmp += '		.animate({top: posNews}, vitesseSlideNews);';
					tmp += '		return false;';
					tmp += '	});';
					
					tmp += '	$(".btScrollDownNews").click(function(){';
					tmp += '	';
					tmp += '		if((posNews - posPlusNews)<maxHauteurNews){';
					tmp += '			posNews = maxHauteurNews;	';
					tmp += '		} else {';
					tmp += '			posNews -= posPlusNews;';
					tmp += '		}';
					
					tmp += '		$("#listeNews")';
					tmp += '		.animate({top: posNews}, vitesseSlideNews);';
					tmp += '		return false;';
					tmp += '	});';
					
					tmp += '	}';
					
					eval (tmp);
					
				}
					
		});
		
	}
}

function affichContent(Niveau1,Niveau2,Niveau3) {
	
	load = 0;
	// AFFICHE RUBRIQUE / RECHARGE OU PAS LE FICHIER CONTENT
	if(Niveau1Display != Niveau1){
		load = 1;
	}
	
	if(load == 1){
		document.getElementById("slidebox").innerHTML = '<div id="wait">chargement</div>';
		document.getElementById("slidebox").style.right = '0px';
		
		var pageUrl="site/ajax/affichContent.php";
		
		if(typeof ActiveXObject == 'undefined') // FIREFOX
		{
			xmlHttpRequest = new XMLHttpRequest();
			xmlHttpRequest.onload = writeContent;
		}
		else // IE
		{
			xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			xmlHttpRequest.onreadystatechange = writeContent;
		}
	
		xmlHttpRequest.open("POST", pageUrl, true);
		xmlHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		
		dataContent = "&Niveau1="+Niveau1;
		if(Niveau2) dataContent = dataContent + "&Niveau2="+Niveau2;
		
		affichMenu(Niveau1,Niveau2);
		
		xmlHttpRequest.send(dataContent);
		
	}
	
	affichTitre(Niveau1,Niveau2,Niveau3);
	
	Niveau1Display = Niveau1;
	Niveau2Display = Niveau2;
	Niveau3Display = Niveau3;

}

function writeTitre(str){
	if(xmlHttpRequest2.readyState==4 || xmlHttpRequest2.readyState=="complete") {  
		
		tmpRetour = xmlHttpRequest2.responseText.split("##");
		document.getElementById("titre").innerHTML = tmpRetour[0];
		document.getElementById("titre").style.background = 'url(site/img/titre/titre'+tmpRetour[1]+'.jpg) no-repeat';

	}
}

function affichTitre(Niveau1,Niveau2,Niveau3){
	// AFFICHER LE TITRE
	var pageUrl2="site/ajax/affichTitre.php";
	
	if(typeof ActiveXObject == 'undefined') // FIREFOX
	{
		xmlHttpRequest2 = new XMLHttpRequest();
		xmlHttpRequest2.onload = writeTitre;
	}
	else // IE
	{
		xmlHttpRequest2 = new ActiveXObject("Microsoft.XMLHTTP");
		xmlHttpRequest2.onreadystatechange = writeTitre;
	}

	xmlHttpRequest2.open("POST", pageUrl2, true);
	xmlHttpRequest2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	
	dataTitre = "&Niveau1="+Niveau1 + "&Niveau2="+Niveau2 + "&Niveau3="+Niveau3;
	
	xmlHttpRequest2.send(dataTitre);
}

function writeMenu(str){
	if(xmlHttpRequest3.readyState==4 || xmlHttpRequest3.readyState=="complete") {  
		
		document.getElementById("menu").innerHTML = xmlHttpRequest3.responseText;
		
		var tailleMoveSlide=1100;
		var vitesseSlide='slow';
		
		var n2 = 0;
		var nom2 = Niveau1Display;
		if(Niveau3Display != ''){
			nom2 = nom2 + '_' + Niveau2Display;
		}

		for(j=0;j<12;j++){
			tmpEval = '$(".slide_'+j+'").click(function(){';
			tmpEval = tmpEval + '$("#slidebox")';
			tmpEval = tmpEval + '.animate({right: tailleMoveSlide*'+j+'}, vitesseSlide);';
			tmpEval = tmpEval + 'return false;';
			tmpEval = tmpEval + '});';
			
			eval(tmpEval);
		}

	}
}

function affichMenu(Niveau1,Niveau2){
	// AFFICHER LE MENU
	var pageUrl2="site/ajax/affichMenu.php";
	
	if(typeof ActiveXObject == 'undefined') // FIREFOX
	{
		xmlHttpRequest3 = new XMLHttpRequest();
		xmlHttpRequest3.onload = writeMenu;
	}
	else // IE
	{
		xmlHttpRequest3 = new ActiveXObject("Microsoft.XMLHTTP");
		xmlHttpRequest3.onreadystatechange = writeMenu;
	}

	xmlHttpRequest3.open("POST", pageUrl2, true);
	xmlHttpRequest3.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	
	dataMenu = "&Niveau1="+Niveau1 + "&Niveau2="+Niveau2;
	
	xmlHttpRequest3.send(dataContent);
}

var xmlHttpRequest;
var xmlHttpRequestContact;
var Niveau1Display;
var Niveau2Display;
var Niveau3Display;
