// JavaScript Document

/* determining whether msie or netscape being used and what versions */
var IE4 = (document.all && !document.getElementById) ? 1 : 0;
var NS4 = (document.layers) ? 1 : 0;
var IE5 = (document.all && document.getElementById) ? 1 : 0;
var N6 = (document.getElementById && !document.all) ? 1 : 0;
var ie = (IE4 || IE5) ? 1 : 0;
var n = (NS4 || N6) ? 1 : 0;
var IE5MAC = false;
var NS4MAC = false;

var MAC = (navigator.userAgent.indexOf("Mac")) // determines platform

if (MAC != -1)
{
	if (IE5)
	{
		IE5MAC = true; //determines if ie5 on a mac
	}
	else
	{
		if (NS4 || N6)
		{
			NS4MAC = true; // determines if net 4 or 6 on mac
		}
	}
}
else
{
}

/* error handling */
window.onerror = errorHandler;
function errorHandler()
{
	return true;
}

function showMenu()
{
	document.getElementById("dropMenu").style.visibility = "visible";
	document.getElementById("dropMenu").style.zIndex = "3";
	tempVar = "menuOn";	
}

function hideMenu()
{
	document.getElementById("dropMenu").style.visibility = "hidden";
	tempVar = "menuOff";
	checkLight();
}

function checkLight()
{
	if (tempVar == "menuOff")
	{
		if (document.getElementById("aboutUs") == null)
		{
			document.getElementById("topnavAboutus").style.color = '#fff';	
		}
	}
	else
	{
		document.getElementById("topnavAboutus").style.color = '#000';
	}
}

/* no of items in each dropdown specified in initial js files */
function menuMovementEvent(e)
{
	var aa 		= "" + findPosX(document.getElementById("topnavAboutus")) + ""; // to start position of menu (X-coord)
	var bb 		= "160"; 	// menu width
	var cc 		= "" + findPosY(document.getElementById("topnavAboutus")) + ""; // start of top of menu (top Y-coord)
	var xStart 	= "" + findPosX(document.getElementById("topnavAboutus")) + ""; 	//specifies X-coord start menu region
	var yStart 	= "" + findPosY(document.getElementById("topnavAboutus")) + ""; // specifies Y-coord start of menu region 
	var yEnd 	= "310" 	// specifies bottom Y-coord
		
	var part2 = xStart.length;
	if (IE5MAC)
	{
		var part3 = part2 + 2;
	}
	else
	{
		var part3 = part2 - 2;		
	}
	var part = xStart.substring(0,part3);		
	var xStart = eval(aa) + eval(part); // specifies X-coord start of menu region
	var xEnd = eval(bb) + eval(xStart); // specifies X-coord end of menu region 
	
	if (tempVar == "menuOn")
	{
		
		if (IE4 || IE5)
		{
			mX = event.clientX;
			mY = event.clientY;
			mXOff = document.body.scrollLeft;
			mYOff = document.body.scrollTop;
			mXX = mX + mXOff;
			mYY = mY + mYOff;
			if (document.documentElement && document.documentElement.scrollTop)
				theTop = document.documentElement.scrollTop;
			else if (document.body)
				theTop = document.body.scrollTop;			

			xStartX = parseInt(xStart) - parseInt(document.body.scrollLeft);
			xEndX = parseInt(xEnd) + parseInt(document.body.scrollLeft);
			yStartY = parseInt(yStart) - parseInt(theTop);
			yEndY = parseInt(yEnd) + parseInt(theTop);
		}
		else
		{
			mX = e.pageX;
			mY = e.pageY;
			mXOff = window.pageXOffset;
			mYOff = window.pageYOffset;
			mXX = mX + mXOff;
			mYY = mY + mYOff;
			xStartX = parseInt(xStart) - parseInt(window.pageXOffset);
			xEndX = parseInt(xEnd) + parseInt(window.pageXOffset);
			yStartY = parseInt(yStart) - parseInt(window.pageYOffset);
			yEndY = parseInt(yEnd) + parseInt(window.pageYOffset);
		}
		if ((mXX <= xStartX) || (mXX >= xEndX))
		{
			//alert("hi");
			hideMenu();
		}
		if ((mYY <= yStartY) || (mYY >= yEndY))
		{
			hideMenu();
	 	}
	}
	
}

/* this is a work a round for the netscape resize bug */
if (document.layers)
{
	origWidth = innerWidth;
	origHeight = innerHeight;
}

function correctResize()
{
	if (innerWidth != origWidth || innerHeight != origHeight)
	location.reload();
}
if (document.layers) onResize = correctResize;

if (IE4 || IE5 || N6)
{
	document.onmousemove = menuMovementEvent;
}	

function initMenu () {
	
	hideMenu();
	/*document.getElementById("menu").style.margin ="0";*/
	//When javascipt enabled drop down class changes appearance
		//this has been moved under the populateheight() funtion
	//document.getElementById("dropMenuWho").className = "dropMenuJS800"; 
	document.getElementById("ddUL").className  = "menuDropStyleJS";
	document.getElementById("ddLi1").className = "menuDropStyleLIJS";
	document.getElementById("ddLi2").className = "menuDropStyleLIJS";
	document.getElementById("ddLi3").className = "menuDropStyleLIJS";
	document.getElementById("ddLi4").className = "menuDropStyleLIJS";
	addMenuEvents();
}

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }


function addMenuEvents () {		
	document.getElementById("ddUL").onmouseover 			= function(){showMenu();};
	document.getElementById("greyBanner").onmouseover 		= function(){hideMenu();};
	document.getElementById("topnavAboutus").onmouseover	= function(){showMenu();};
	document.getElementById("topnav-home").onmouseover 		= function(){hideMenu();};
	document.getElementById("topnav-actualite").onmouseover	= function(){hideMenu();};
	
	
}

function populateHeight() {
	
	if (screen.height>768) {		
		
		if (document.body.clientHeight) {
				if (navigator.userAgent.indexOf("Firefox")!=-1) {
					document.getElementById("outerHolding").style.minHeight = screen.height - 495 + "px";
				}
				else if (navigator.userAgent.indexOf("Opera")!=-1	) {
					
							document.getElementById("outerHolding").style.minHeight = screen.height - 400 + "px";			
				}  else if (navigator.userAgent.indexOf("MSIE 7.0")!=-1	) {
						
							document.getElementById("outerHolding").style.minHeight = screen.height - 395 + "px";
						
				}else {
					
							document.getElementById("outerHolding").style.height = screen.height - 410 + "px";									
						
				}
			
		}
	}
	document.getElementById("dropMenuWho").className = "";
	document.getElementById("dropMenuWho").style.position = "absolute";
	document.getElementById("dropMenuWho").style.top 	= ""+ (findPosY(document.getElementById("topnavAboutus")) + 23 ) + "px";
	document.getElementById("dropMenuWho").style.left = "" + findPosX(document.getElementById("topnavAboutus")) + "px";
}

function init (){	
	initMenu();		
	if (document.getElementById("img1") != null) {
		
		document.getElementById("rotate1").style.display = "block";		
		
		startRotate();	
	}	
	populateHeight();
	for (var i=1; i<5;i++) {
		if (document.getElementById("link" + [i]) != null)	{
			document.getElementById("link" + [i]).target = "_blank";
		}	
		else{
			break;
		}
	}	
}

window.onload = init;



