// JavaScript Document

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function(){insertMidis();});
//addLoadEvent(function(){afficheMenu();});
addLoadEvent(function(){testWidth();});
window.onresize=function(){testWidth();}
addLoadEvent(function(){intDep=setInterval(mouseoverLiens,1000)});
addLoadEvent(function(){pop();});
addLoadEvent(function(){news();});
addLoadEvent(function(){defilNews();});
addLoadEvent(function(){if(d==0)rolloverLang();});
//addLoadEvent(function(){son(true);});

/*function son(bool)
{
	if(bool)
	{
		document.getElementById("son").onclick=function()
		{
			this.src=this.src.substring(0,this.src.indexOf("sonof"))+"sonon"+this.src.substring(this.src.indexOf("sonof")+5);
			this.alt="Sound on";
			delete this.onclick;
			son(false);
			objFlash.clipLabelgotoAndStop("sonsRollover","f");
			for(i=0;i<tabLiens.length;i++)
			{
				delete tabLiens[i].onmouseover;
			}
		}
	}
	else
	{
		document.getElementById("son").onclick=function()
		{
			this.src=this.src.substring(0,this.src.indexOf("sonon"))+"sonof"+this.src.substring(this.src.indexOf("sonon")+5);
			this.alt="Sound of";
			delete this.onclick;
			son(true);
			objFlash.clipLabelgotoAndStop("sonsRollover","g");
			mouseoverLiens();
		}
	}

}
*/
function pop()
{
	tabLiens=document.getElementsByTagName("a");
	for(i=0;i<tabLiens.length;i++)
	{
		if(tabLiens[i].className)
		{
			if(tabLiens[i].className=="blank")
			tabLiens[i].onclick=function()
			{
				window.open(this.href);
				return false;
			}
		}
	}
}

function news()
{
	if(page=="news")
	{
	if(document.getElementById("interview"))
		document.getElementById("interview").onclick=function()
		{
		objFlash.clipStop('_root.lignes');
		document.getElementById("iframeNews").style.display="none";

		obj=document.createElement("object");
		param1=document.createElement("param");
		param1.name="src";
		param1.value=this.href;
		
		param2=document.createElement("param");
		param2.name="autoplay";
		param2.value="true";
		
		obj.appendChild(param1);
		obj.appendChild(param2);
		
		dmb=document.createElement("div");
		dmb.id="dansmaboite";
		
		fermer=document.createElement("img");
		fermer.id="fermer";
		fermer.src="../../res/img/fermer.gif";
		fermer.alt="Fermer la vidéo";
		fermer.title="Fermer la vidéo" ;
		
		dmb.appendChild(fermer);
		dmb.appendChild(obj);
		
		document.getElementById("contmenus").appendChild(dmb);
		
		obj.type="video/x-ms-wmv";
		obj.data=this.href;;
		obj.autoplay="true";

		document.getElementById("fermer").onclick=function()
		{
			go("news.php",this);
			//return false;
					//window.location.href="news.php";
		}
		
		return false;
		}
		
		
		/////////Click depuis la bande de texte
		if (document.URL.indexOf("iframe") && document.URL.indexOf("iframe")!=-1)
		document.getElementsByTagName("iframe")[0].src=document.URL.substring(document.URL.indexOf("iframe")+7);
	}
}

function insertMidis()
{
	d==0? ad="": ad="../../";

	insertFlash(ad+"res/midiscom.swf?d="+d+"&p="+p+"&langue="+langue+"&page="+page, "flash", 1, "contflash", 1004, 427)	;
	
	//insertFlash(ad+"res/testaudio.swf?d="+d+"&p="+p, "flash", 1, "contflash", 1004, 427);
}

function defilNews()
{
		//alert(document.getElementById("txtnews").textContent.length);

	intN=setInterval("def()",20);
	document.getElementById("txtnews").onmouseover=function()
	{
		clearInterval(intN);
		intN=setInterval("def()",80);
	}
	document.getElementById("txtnews").onmouseout=function()
	{
		clearInterval(intN);
		intN=setInterval("def()",20);
	}
	//alert(document.getElementById("txtnews").getElementsByTagName("a").length);
	for(i=0;i<document.getElementById("txtnews").getElementsByTagName("a").length;i++)
	{
		document.getElementById("txtnews").getElementsByTagName("a")[i].onclick=function()
		{
			//alert("pages/"+langue+"/news.php?p="+p+"&iframe="+this.href);
			//"pages/"+lang+/"news.php?p="+p+"&iframe="+this.href;
			window.location.href="pages/"+langue+"/news.php?p="+p+"&iframe="+this.href;
			return false;
		}
	}
}
function def()
{
//	alert(getStyle("txtnews","width"));
	var l=document.getElementById("txtnews").style.left;
	if(!l)l=document.getElementById("txtnews").style.left="1004px";
	document.getElementById("txtnews").style.left=Number(parseInt(l)-1)+"px";
	
	typeof(document.getElementById("txtnews").innerText)!="undefined"? longueur=document.getElementById("txtnews").innerText.length: longueur=document.getElementById("txtnews").textContent.length
	if(parseInt(l)<-longueur*5)document.getElementById("txtnews").style.left="1004px";
}

function rolloverLang()
{
	im1=new Image();im1.src="res/img/fr2.gif";
	im2=new Image();im2.src="res/img/en2.gif";
	im3=new Image();im3.src="res/img/it2.gif";
	
	
	document.getElementById("fr").onmouseover=function()
	{
		//alert(this.getElementsByTagName("img")[0].src);
		im10=this.getElementsByTagName("img")[0].src;
		this.getElementsByTagName("img")[0].src=im1.src;
	}
	document.getElementById("fr").onmouseout=function()
	{
		this.getElementsByTagName("img")[0].src=im10;
	}
	document.getElementById("en").onmouseover=function()
	{
		im20=this.getElementsByTagName("img")[0].src;
		this.getElementsByTagName("img")[0].src=im2.src;
		//alert(im20);
	}
	document.getElementById("en").onmouseout=function()
	{
		this.getElementsByTagName("img")[0].src=im20;
	}
	document.getElementById("it").onmouseover=function()
	{
		im30=this.getElementsByTagName("img")[0].src;
		this.getElementsByTagName("img")[0].src=im3.src;
	}
	document.getElementById("it").onmouseout=function()
	{
		this.getElementsByTagName("img")[0].src=im30;
	}
}

function testWidth()
{
	var w;
	window.innerWidth? w=window.innerWidth: w=document.body.clientWidth;
	w<1005? document.getElementById("contmenus").style.position="static": document.getElementById("contmenus").style.position="absolute";
}

function appTxt(j)
{
	//document.getElementById('contmenus').getElementsByTagName('img')[j].style.display='block';
	if(document.getElementById('sysimage'))document.getElementById('sysimage').style.display='block';
	if(document.getElementById('syschema'))document.getElementById('syschema').style.display='block';
/*	for(i=0;i<document.getElementsByTagName('img').length;i++)
	{
		if(document.getElementsByTagName('img')[i].className=="imgtop")
		{
			document.getElementsByTagName('img')[i].style.display="inline";
			//alert('il');
		}
	}*/
}
		

function afficheMenu()
{
	document.getElementById("midiscom").style.display="block";
	m=document.getElementById("menu");
	if(d==0)
	{
		var cst=0;
	}
	else
	{
		var cst=0;
		if(d==1 || d==6) var i=1
		else var i=2;
		for(j=i;j<m.getElementsByTagName("a").length;j++)
		{
			m.getElementsByTagName('a')[j].style.top='80px';
		}
		//document.getElementById('contenus').style.display='none';
		setTimeout("document.getElementById('contenus').style.display='block';",1000);
		for(i=0;i<document.getElementsByTagName('img').length;i++)
		{
			setTimeout("appTxt("+i+")",1000);
		}
		
		if(typeof page != "undefined")
		if(page== "midiscom")objFlash.clipPlay('lignes');
		if(page=="systeme")setTimeout("objFlash.clipLabelgotoAndStop('systemes','a')",1200);

	}
	for(var i=0;i<m.getElementsByTagName("a").length;i++)
	{
		//m.getElementsByTagName('a')[i].style.display='none';
		setTimeout("m.getElementsByTagName('a')["+i+"].style.display='block';",200*i+cst);
	}
	
	if(document.getElementById('et'))setTimeout("document.getElementById('et').style.display='block';",cst*2);

}
function insertFlash(data, id, place, insert, w, h)
{
	//alert(rub);
	//alert(index);
	var h=h;
	var objetFlash=document.createElement("object");

	
	var paramMovie=document.createElement("param");
	paramMovie.setAttribute("name","movie");
	paramMovie.setAttribute("value",data);
	
	var paramQuality=document.createElement("param");
	paramQuality.setAttribute("name","quality");
	paramQuality.setAttribute("value","high");
	
	var paramWmode=document.createElement("param");
	paramWmode.setAttribute("name","wmode");
	paramWmode.setAttribute("value","transparent");
	
	objetFlash.appendChild(paramMovie);
	objetFlash.appendChild(paramQuality);
	objetFlash.appendChild(paramWmode);

	place==1?document.getElementById(insert).insertBefore(objetFlash,document.getElementById(insert).firstChild):
		document.getElementById(insert).appendChild(objetFlash);

//	alert(document.getElementById("flashtetiere").innerHTML);
	objetFlash.setAttribute("width",w);
	objetFlash.setAttribute("height",h);
	objetFlash.setAttribute("style","position: static;");
	objetFlash.setAttribute("id",id);
	objetFlash.setAttribute("type","application/x-shockwave-flash");
	objetFlash.setAttribute("data",data);
	
	// Creation d'un nouvel objet flash pour contrôle depuis javascript
	objFlash = new flashID('flash'); // anim = l'identifiant (id) de l'animation

	
}

function mouseoverLiens()
{
	lienJaune=document.getElementById('lien2').href;
	lienBleu=document.getElementById('lien3').href;
	lienRose=document.getElementById('lien4').href;
	lienVert=document.getElementById('lien5').href;

	objFlash.setVariable('lienJaune',lienJaune);
	objFlash.setVariable('lienBleu',lienBleu);
	objFlash.setVariable('lienRose',lienRose);
	objFlash.setVariable('lienVert',lienVert);

	if(typeof(intDep)!="undefined")
	{
		clearInterval(intDep);
	}
	if(typeof(emo)!="undefined")
	{
		clearInterval(emo);
		objFlash.clipgotoAndStop("sonsRollover",1);
	}
	//alert('mol');
	tabLiens=document.getElementsByTagName("a");
	for(i=0;i<tabLiens.length;i++)
	{
		if(tabLiens[i].parentNode.parentNode.id!="txtnews" && tabLiens[i].id!="interview")
		{
			tabLiens[i].onclick=function()
			{
				if(d!=0)
				{
					//alert(d);
					go(this.href,this);
					return false;
				}
				switch(this.id)
				{
					case "lien1": objFlash.clipLabelgotoAndStop("sonsRollover","a");break;
					case "lien2": objFlash.clipLabelgotoAndStop("sonsRollover","b");break;
					case "lien3": objFlash.clipLabelgotoAndStop("sonsRollover","c");break;
					case "lien4": objFlash.clipLabelgotoAndStop("sonsRollover","d");break;
					case "lien5": objFlash.clipLabelgotoAndStop("sonsRollover","e");break;
					default: objFlash.clipLabelgotoAndStop("sonsRollover","a");break;
				}
			}
		}
		if(tabLiens[i].parentNode.parentNode.id!="lang")
		tabLiens[i].onmouseover=function()
		{
			for(i=0;i<tabLiens.length;i++)
			{
				if(document.getElementsByTagName("a")[i].onmouseover)
					document.getElementsByTagName("a")[i].onmouseover=function(){this.onmouseover=null;};
					
			}
			//delete this.onmouseover;
			if(typeof(emo)!="undefined")clearInterval(emo);
			emo=setInterval(mouseoverLiens,1000);
				
			if(this.href.indexOf("messages")!=-1 && d!=0)objFlash.clipLabelgotoAndStop("sonsRollover","b")
			else
				if((this.href.indexOf("musiques")!=-1  && d!=0)|| this.href.indexOf("audio")!=-1)objFlash.clipLabelgotoAndStop("sonsRollover","c")
				else
					if((this.href.indexOf("images" )!=-1 && d!=0)|| this.href.indexOf("video")!=-1)objFlash.clipLabelgotoAndStop("sonsRollover","d")
					else
						if(this.href.indexOf("senteur")!=-1 && d!=0)objFlash.clipLabelgotoAndStop("sonsRollover","e")
						else
							if(this.href.indexOf("messages")==-1 && this.href.indexOf("musiques")==-1  && this.href.indexOf("senteur")==-1 && this.href.indexOf("images" )==-1)
							{
								objFlash.clipLabelgotoAndStop("sonsRollover","a");
								//alert(this.parentNode.parentNode.id);
							}

			this.onmouseover=function(){};
		}
	}
}

function mouseOverFlash(num)
{
	if(typeof(intMOF)!="undefined")clearInterval(intMOF);
	document.getElementById('lien2').style.color='black';
	document.getElementById('lien3').style.color='black';
	document.getElementById('lien4').style.color='black';
	document.getElementById('lien5').style.color='black';
	
	if(num!=-1)
	{
		document.getElementById('lien'+num).style.color='white';
		intMOF=setInterval(mouseOverFlash, 2000, -1);
	}
	
	
}

function go(adresse,lien)
{
	//alert(adresse);
	objFlash.play();
	objFlash.setVariable('adresse',adresse);
	document.getElementById("contmenus").style.display="none";
	//document.getElementById("flash").style.display="none";
	for(j=0;j<tabLiens.length;j++)
	{
		if(tabLiens[j]!=lien)tabLiens[j].style.display="none";
	}
	//setTimout("alert('"+adresse+"')",1500);
}


	
var flashID = function(id) 
{
	 this.id = id

	 var log_erreur = new Array("Erreur","Paramètre faux ou manquant");

	 monswf = document.getElementById(id);
	// alert(id);
 
	 this.play = function play()
	 {
		 monswf.Play();
	 }
	this.gotoAndStop = function gotoAndStop(frame)
	{
		 if(!frame){window.alert(log_erreur[1]); return;}
		 monswf.GotoFrame(frame);
	 }
	 this.currentLabel = function currentLabel(Clip) 
	 {
		 if(!Clip){window.alert(log_erreur[1]); return;}
		 return monswf.TCurrentLabel(Clip);
	 }
     this.clipgotoAndStop = function clipgotoAndStop(Clip,frame) 
	 {
		 if(!Clip||!frame){window.alert(log_erreur[1]); return;}
		 monswf.TGotoFrame(Clip,frame-1);
     }
	 this.clipLabelgotoAndStop = function clipLabelgotoAndStop(Clip,label) 
	 {
		 if(!Clip||!label){window.alert(log_erreur[1]); return;}
		 monswf.TGotoLabel(Clip,label);
	 }
	 this.setVariable = function SetVariable(nom,valeur) 
	 {
		 if(!nom||valeur==null){window.alert(log_erreur[1]); return;}
		 monswf.SetVariable(nom,valeur);
	 }
	 this.clipStop = function clipStop(Clip) 
	 {
		 if(!Clip){window.alert(log_erreur[1]); return;}
		 monswf.TStopPlay(Clip);
	 }
	this.clipPlay = function clipPlay(Clip)
	{
		 if(!Clip){window.alert(log_erreur[1]); return;}
		 monswf.TPlay(Clip);
	 }
}

/////////////////////////////////////////////////////////////////////
/*
function makeRequest(url) {

	var httpRequest = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType) {
			httpRequest.overrideMimeType('text/xml');
			// Voir la note ci-dessous à propos de cette ligne
		}
	}
	else if (window.ActiveXObject) { // IE
		try {
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {}
		}
	}

	if (!httpRequest) {
		alert('Abandon :( Impossible de créer une instance XMLHTTP');
		return false;
	}
	httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
	httpRequest.open('GET', url, true);
	httpRequest.send(null);

}

function alertContents(httpRequest) {

	if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) {
			
			var xmldoc = httpRequest.responseXML;
		//	alert(xmldoc.data)
			
			alert(xmldoc.getElementsByTagName('a').length);
			for(i=0;i<xmldoc.getElementsByTagName('a').length;i++)
			{
				if(xmldoc.getElementsByTagName('a')[i].className=="resum_tit")
				{
					alert(xmldoc.getElementsByTagName('a')[i].textContent);
				}
			}
			
		} else {
			alert('Un problème est survenu avec la requête.');
		}
	}

}

makeRequest('../../publications/FO/scripts/newsFO_accueil.php?lang=FR')*/


