// 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(){
	borderMenu();
	detectListe();
	evenementListe();
	rolloverMenu("civil");
	rolloverMenu("military");
	//funcFlightSim();
	  fctBlank();
	  fctPop();
	  
	  //fixPng();
});

function fixPng()
{
	if(navigator.appVersion.indexOf('MSIE 6')!=-1)
	{
		for(var i=0; i<document.images.length; i++)
		{
			var img = document.images[i];
			var imgName = img.src.toUpperCase();
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			{
				
				var spanPNGTemp=document.createElement("div");
				spanPNGTemp.id=img.id;
				spanPNGTemp.className=img.className;
				spanPNGTemp.title= (img.title) ? img.title: img.alt;
				
				//alert(img.width);
				
				img.parentNode.appendChild(spanPNGTemp);
				spanPNGTemp.style.width=img.width+"px;";
				spanPNGTemp.style.height=img.height+"px;";
				spanPNGTemp.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img.src+"', sizingMethod='scale')";
				
				img.parentNode.removeChild(img);
			}
		}
 	}
}

function fctPop()
{
	for(var i=0; i<document.getElementsByTagName("a").length; i++)
	{
		if(document.getElementsByTagName("a")[i].className)
			if(document.getElementsByTagName("a")[i].className=="pop" || document.getElementsByTagName("a")[i].className=="popup")
			{
				document.getElementsByTagName("a")[i].onclick=function()
				{
					fen=window.open(this.href,"popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=700,height=500,left=5,top=5");
					fen.focus();
					return false;
				}
			}
	}
}
function fctBlank()
{
	for(var i=0; i<document.getElementsByTagName("a").length; i++)
	{
		if(document.getElementsByTagName("a")[i].className)
			if(document.getElementsByTagName("a")[i].className=="blank")
			{
				document.getElementsByTagName("a")[i].onclick=function()
				{
					window.open(this.href);
					return false;
				}
			}
	}
}

function funcFlightSim()
{
	 document.getElementById("flightSimA").onclick=function()
	 {
		 fen=window.open(this.href,'RMT','menubar=no, status=no, scrollbars=no, menubar=no, width=965, height=695');fen.focus();
		 return false;
	 }
}

function roloverHelico(mcThis)
{
	removeRolH();
	var roloverHelico=document.createElement("div");
	roloverHelico.style.background="url(../../res/img/rollover-helico.png) no-repeat left top";
	if(navigator.appVersion.indexOf("MSIE 6")!=-1)
	roloverHelico.style.background="url(../../res/img/rollover-helico-png8.png) no-repeat left top";

	roloverHelico.style.position="absolute";
	roloverHelico.style.width="93px";
	roloverHelico.style.height="47px";
	
	if(mcThis.parentNode.tagName=="LI")roloverHelico.style.left=mcThis.parentNode.style.left
	else roloverHelico.style.left=mcThis.parentNode.parentNode.parentNode.style.left;
	
	if(parseInt(roloverHelico.style.left)<0)roloverHelico.style.left="-10px";

	
	roloverHelico.style.marginLeft="362px";
	roloverHelico.style.top="95px";
	roloverHelico.style.zIndex="100";
	
	roloverHelico.style.fontSize="11px";
	roloverHelico.style.textAlign="center";
	roloverHelico.style.lineHeight="37px";
	roloverHelico.style.color="#1A4559";
	
	roloverHelico.id="rolH";
	
	txtHelico=document.createTextNode(mcThis.parentNode.getElementsByTagName("img")[0].alt);
	roloverHelico.appendChild(txtHelico);
	
	var parent=document.getElementById("menuI").getElementsByTagName("li")[0].getElementsByTagName("p")[0];
	parent.parentNode.insertBefore(roloverHelico, parent);

//	intRolH=setTimeout("removeRolH(true)", 2000);

}

function evenements(adress, argID)
{
	for(var j=0; j<document.getElementsByTagName("div").length; j++)
	{
		if(document.getElementsByTagName("div")[j].id)
		{
			if(document.getElementsByTagName("div")[j].id==argID)
			{
				document.getElementsByTagName("div")[j].onclick=function()
				{
					alert(adress);
					window.location.href=adress;
				}
				document.getElementsByTagName("div")[j].onmouseout=function()
				{
					this.parentNode.removeChild(this);
				}
			}
		}
	}
}

function afficheImageRollOver(mcThis, menu, argEvenements, etat)
{
	if(document.getElementById("rolover-products"))
	document.getElementById("rolover-products").parentNode.removeChild(document.getElementById("rolover-products"));
	
	var adress=mcThis.href;
	var imgRoll=document.createElement("div");
	imgRoll.style.background="url(../../res/img/rollover-products.png) no-repeat left top";
	if(argEvenements==true)imgRoll.id="rolover-products";
	else imgRoll.id="select"+menu;
	imgRoll.style.position="absolute";
	imgRoll.style.width="59px";
	imgRoll.style.height="48px";

	if(navigator.appVersion.indexOf("MSIE 6")!=-1)
	{
		imgRoll.style.background="none";
		setTimeout('document.getElementById("'+imgRoll.id+'").style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'../../res/img/rollover-products.png\', sizingMethod=\'scale\')"',80);
		
	}
	if(navigator.appVersion.indexOf("MSIE")!=-1)
	{
		imgRoll.style.marginLeft="-60px";
	}
	imgRoll.style.cursor="pointer";
	mcThis.parentNode.insertBefore(imgRoll, mcThis);
	
	if(argEvenements==true)evenements(adress,"rolover"+menu);
		
	if(etat=="strong")
	{
		imgRoll.onmouseover=function()
		{
			roloverHelico(this.parentNode.getElementsByTagName("img")[0]);
		}
	}
	else
	{
		imgRoll.onmouseout=function()
		{
			this.parentNode.removeChild(this);
			removeRolH();
		}
	}
	imgRoll.onclick=function()
	{
		window.location=this.parentNode.getElementsByTagName("a")[0].href;
	}
}

function rolloverMenu(statut)
{
	menu="menu"+statut;
	imgrollover=new Object();
	imgrollover.src="../../res/img/rollover-products-menuV.png";
	for(var i=0; i< document.getElementById(menu).getElementsByTagName("a").length; i++)
	{
		document.getElementById(menu).getElementsByTagName("a")[i].onmouseover=function()
		{
			afficheImageRollOver(this, menu, true, "over");
			roloverHelico(this);
		}
	}
}

function deplacement(avant, statut)
{
	var menu="menu"+statut;
	avant==true? valeur=-5: valeur=5;
	
	for(var i=0;i<document.getElementById(menu).getElementsByTagName("li").length;i++)
	{
		document.getElementById(menu).getElementsByTagName("li")[i].style.left=String(parseInt(document.getElementById(menu).getElementsByTagName("li")[i].style.left)+valeur)+"px";
		if(parseInt(document.getElementById(menu).getElementsByTagName("li")[i].style.left)>60*4)
		{
			document.getElementById(menu).getElementsByTagName("li")[i].style.display="none";
		}
		else
		{
			document.getElementById(menu).getElementsByTagName("li")[i].style.display="block";
		}
	}
	if(parseInt(document.getElementById(menu).getElementsByTagName("li")[0].style.left)<0 && !document.getElementById("flechegauche"+statut))
	{
		flechegauche=document.createElement("img");
		flechegauche.src="../../res/img/fleche-gauche-"+statut+".png";
		flechegauche.style.position="absolute";
		flechegauche.style.left="670px";
		flechegauche.style.top="123px";
		flechegauche.title="See the previous Aircrafts";
		flechegauche.style.cursor="pointer";
		flechegauche.style.zIndex=21;
		flechegauche.id="flechegauche"+statut;
		document.getElementById("flechedroite"+statut).parentNode.insertBefore(flechegauche, document.getElementById("flechedroite"+statut));
		
		document.getElementById("flechegauche"+statut).onmouseover=function()
		{
			removeRolH(true);
			intDeplacement=setInterval("deplacement(false, '"+statut+"')", 80)
		}
		document.getElementById("flechegauche"+statut).onmouseout=function()
		{
			clearInterval(intDeplacement);
		}
	}
	if(parseInt(document.getElementById(menu).getElementsByTagName("li")[0].style.left)>0 && document.getElementById("flechegauche"+statut))
	{
		for(var i=0;i<document.getElementById(menu).getElementsByTagName("li").length;i++)
		{
			document.getElementById(menu).getElementsByTagName("li")[i].style.left=String(i*60)+"px";		
			if(parseInt(document.getElementById(menu).getElementsByTagName("li")[i].style.left)>60*4)
			{
				document.getElementById(menu).getElementsByTagName("li")[i].style.display="none";
			}
			else
			{
				document.getElementById(menu).getElementsByTagName("li")[i].style.display="block";
			}
		}
		document.getElementById("flechegauche"+statut).parentNode.removeChild(document.getElementById("flechegauche"+statut));
		clearInterval(intDeplacement);
	}
	if(parseInt(document.getElementById(menu).getElementsByTagName("li")[document.getElementById(menu).getElementsByTagName("li").length-1].style.left)<4*60 && document.getElementById("flechedroite"+statut))
	{
		document.getElementById("flechedroite"+statut).parentNode.removeChild(document.getElementById("flechedroite"+statut));
		clearInterval(intDeplacement);
	}
	else
	if(!document.getElementById("flechedroite"+statut))
	{
		creationFlecheDroite(statut);
	}
}

function removeRolH(rol)
{
	if(typeof(intRolH)!="undefined"){
		clearInterval(intRolH);
	}
	
	if(document.getElementById("rolH"))
		document.getElementById("rolH").parentNode.removeChild(document.getElementById("rolH"));
		if(rol)removeRol();
}

function removeRol()
{
	if(document.getElementById("rolover-products"))
	document.getElementById("rolover-products").parentNode.removeChild(document.getElementById("rolover-products"));
}

function creationFlecheDroite(statut)
{
	var menu="menu"+statut;
	if(document.getElementById(menu).getElementsByTagName("li").length>4)
	{
		flechedroite=document.createElement("img");
		flechedroite.src="../../res/img/fleche-droite-"+statut+".png";
		flechedroite.style.position="absolute";
		flechedroite.style.left="695px";
		flechedroite.style.top="123px";
		flechedroite.title="See the other Aircrafts";
		flechedroite.style.cursor="pointer";
		flechedroite.style.zIndex=20;
		flechedroite.id="flechedroite"+statut;
		document.getElementById("menuI").getElementsByTagName("p")[0].parentNode.insertBefore(flechedroite, document.getElementById("menuI").getElementsByTagName("p")[0]);
		
		document.getElementById("flechedroite"+statut).onmouseover=function()
		{
			removeRolH(true);
			intDeplacement=setInterval("deplacement(true, '"+statut+"')", 80);
		}
		document.getElementById("flechedroite"+statut).onmouseout=function()
		{
			clearInterval(intDeplacement);
		}
	}

}

function initDeplacement(statut)
{
	if(document.getElementById("flechedroitecivil"))document.getElementById("flechedroitecivil").parentNode.removeChild(	document.getElementById("flechedroitecivil"));
	if(document.getElementById("flechegauchecivil"))document.getElementById("flechegauchecivil").parentNode.removeChild(	document.getElementById("flechegauchecivil"));
	if(document.getElementById("flechedroitemilitary"))document.getElementById("flechedroitemilitary").parentNode.removeChild(	document.getElementById("flechedroitemilitary"));
	if(document.getElementById("flechegauchemilitary"))document.getElementById("flechegauchemilitary").parentNode.removeChild(	document.getElementById("flechegauchemilitary"));

	var menu="menu"+statut;
	for(var i=0;i<document.getElementById(menu).getElementsByTagName("li").length;i++)
	{
		document.getElementById(menu).getElementsByTagName("li")[i].style.position="absolute";
		document.getElementById(menu).getElementsByTagName("li")[i].style.left=String(i*60)+"px";
		if(parseInt(document.getElementById(menu).getElementsByTagName("li")[i].style.left)>4*60)
		document.getElementById(menu).getElementsByTagName("li")[i].style.display= "none";
	}
	creationFlecheDroite(statut);
}


function evenementListe()
{
	var oldCivilBg;
	var oldMilitBg;
	document.getElementById("menuCivMit").getElementsByTagName("li")[0].onclick=function()
	{
		afficheListe("c");
		document.getElementById("infosHelico").style.display="none";
	}
	document.getElementById("menuCivMit").getElementsByTagName("li")[0].onmouseover=function()
	{
		this.style.background="#00679B";
	}
	document.getElementById("menuCivMit").getElementsByTagName("li")[0].onmouseout=function()
	{
		if(liste!="civil")this.style.background="#547483";
	}
	for(var i=1;i<document.getElementById("menuCivMit").getElementsByTagName("li").length;i++)
	{
		if(document.getElementById("menuCivMit").getElementsByTagName("li")[i].parentNode.id)
		{
			if(document.getElementById("menuCivMit").getElementsByTagName("li")[i].parentNode.id=="menuCivMit")
			{
				document.getElementById("menuCivMit").getElementsByTagName("li")[i].onclick=function()
				{
					afficheListe("m");
					document.getElementById("infosHelico").style.display="none";
				}
				document.getElementById("menuCivMit").getElementsByTagName("li")[i].onmouseover=function()
				{
					this.style.background="#6D955B";
				}
				document.getElementById("menuCivMit").getElementsByTagName("li")[i].onmouseout=function()
				{
					if(liste!="military")this.style.background="#547483";
				}
			}
		}
	}
}

var liste;
function detectListe()
{
	for(var i=0; i<document.getElementById("menucivil").getElementsByTagName("li").length; i++)
	{
		if(document.getElementById("menucivil").getElementsByTagName("li")[i].getElementsByTagName("strong")[0])
		liste="civil";
	}
	if(liste=="civil")
	{
		afficheListe("c");
		afficheImageRollOver(document.getElementById("menuCivMit").getElementsByTagName("strong")[0].getElementsByTagName("a")[0], "menucivil", false, "strong");
	}
	else
	{
		liste=="military";
		afficheListe("m");
		afficheImageRollOver(document.getElementById("menuCivMit").getElementsByTagName("strong")[0].getElementsByTagName("a")[0], "menumilitary", false, "strong");
	}
	document.getElementById("learnmore").getElementsByTagName("a")[0].style.background="url(../../res/img/learnmore"+liste+".png)";
	for(i=0; i<document.getElementById("missions").getElementsByTagName("a").length; i++)
	{
		document.getElementById("missions").getElementsByTagName("a")[i].style.background="url(../../res/img/puceaccueil"+liste+".png) no-repeat left center";
	}
}

function afficheListe(l)
{
	removeRolH();
	if(l=="c")
	{
		liste="civil";
		document.getElementById("menucivil").style.display="block";
		document.getElementById("menumilitary").style.display="none";
		document.getElementById("aircraftFinder").style.background="#00679B";
		document.getElementById("menuCivMit").getElementsByTagName("li")[0].style.background="none";
		document.getElementById("flecheAccueil").style.background="url(../../res/img/flecheAccueilCivil.png)";
		for(var i=1;i<document.getElementById("menuCivMit").getElementsByTagName("li").length;i++)
		{
			if(document.getElementById("menuCivMit").getElementsByTagName("li")[i].parentNode.id)
			{
				if(document.getElementById("menuCivMit").getElementsByTagName("li")[i].parentNode.id=="menuCivMit")
				{
					document.getElementById("menuCivMit").getElementsByTagName("li")[i].style.background="#547483";
				}
			}
		}
	}
	else
	{
		liste="military";
		document.getElementById("menucivil").style.display="none";
		document.getElementById("menumilitary").style.display="block";
		document.getElementById("aircraftFinder").style.background="#6D955B";
		document.getElementById("menuCivMit").getElementsByTagName("li")[0].style.background="#547483";
		document.getElementById("flecheAccueil").style.background="url(../../res/img/flecheAccueilMilitaire.png)";
		for(var i=1;i<document.getElementById("menuCivMit").getElementsByTagName("li").length;i++)
		{
			if(document.getElementById("menuCivMit").getElementsByTagName("li")[i].parentNode.id)
			{
				if(document.getElementById("menuCivMit").getElementsByTagName("li")[i].parentNode.id=="menuCivMit")
				{
					document.getElementById("menuCivMit").getElementsByTagName("li")[i].style.background="none";
				}
			}
		}
	}
	initDeplacement(liste);

}

function borderMenu()
{
	document.getElementById("menuI").getElementsByTagName("a")[document.getElementById("menuI").getElementsByTagName("a").length-1].style.borderRight=0;
}

