function hehe(e)
{
	//debug('hehe');
	if( getMouseY(e) > 149 )
	{
		window.activeNode.className = window.activeNode.className.replace("ssmenu2_off", "ssmenu2_on");
		document.onmousemove = null;
	}
}

window.onload = function()
{
	initMenu();
	
	var ulnav = document.getElementById("nav2");
	ulnav.onmouseover = function( e )
	{
		if( navigator.userAgent.indexOf('Safari') != -1 )
		{
			//window.timer = setTimeout('hehe(e)',100);
			document.onmousemove = hehe;
		}

		var navRoot = this;
		for (var i=0; i<navRoot.childNodes.length; i++)
		{
			if ( navRoot.childNodes[i].nodeName == "LI") 
			{
				var navRootLi = navRoot.childNodes[i];
				for (var j=0; j<navRootLi.childNodes.length; j++)
				{
					if ( navRootLi.childNodes[j].className == "smenu1_on")
					{
						var navRootLiUl = navRootLi.childNodes[j];
						for (var k=0; k<navRootLiUl.childNodes.length; k++)
						{
							if ( navRootLiUl.childNodes[k].nodeName == "LI") 
							{
								var navRootLiUlLi = navRootLiUl.childNodes[k];
								for (var l=0; l<navRootLiUlLi.childNodes.length; l++)
								{
									if ( navRootLiUlLi.childNodes[l].className == "ssmenu2_on")
									{
										var navRootLiUlLiUl =  navRootLiUlLi.childNodes[l];
										
										window.activeNode = navRootLiUlLiUl;
										
										navRootLiUlLiUl.className=navRootLiUlLiUl.className.replace("ssmenu2_on", "ssmenu2_off");
										//debug( getMouseY(e) );
										/*if( navigator.userAgent.indexOf('Safari') != -1 && )
										{
											//clearTimeout(window.timer);
											//navRootLiUlLiUl.className=navRootLiUlLiUl.className.replace("ssmenu2_off", "ssmenu2_on");
											//document.onmousemove = null;
										}*/
									}
								}
							}
						}
					}
				}
			}
		}
	}
	
	ulnav.onmouseout = function( e )
	{
		var navRoot = this;
		for (var i=0; i<navRoot.childNodes.length; i++)
		{
			if ( navRoot.childNodes[i].nodeName == "LI") 
			{
				var navRootLi = navRoot.childNodes[i];
				for (var j=0; j<navRootLi.childNodes.length; j++)
				{
					if ( navRootLi.childNodes[j].className == "smenu1_on")
					{
						var navRootLiUl = navRootLi.childNodes[j];
						for (var k=0; k<navRootLiUl.childNodes.length; k++)
						{
							if ( navRootLiUl.childNodes[k].nodeName == "LI") 
							{
								var navRootLiUlLi = navRootLiUl.childNodes[k];
								for (var l=0; l<navRootLiUlLi.childNodes.length; l++)
								{
									if ( navRootLiUlLi.childNodes[l].className == "ssmenu2_off")
									{
										var navRootLiUlLiUl =  navRootLiUlLi.childNodes[l];
										navRootLiUlLiUl.className=navRootLiUlLiUl.className.replace("ssmenu2_off", "ssmenu2_on");
										//debug( "rollout" );
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

function initMenu()
{
	startList();
}

startList = function()
{
	if (document.all&&document.getElementById)
	{
		reSizeSousMenu();
		
		var navRoot = document.getElementById("nav2");
		var ulUsages = document.getElementById("ulsmenuusages");
		var ulMarche = document.getElementById("ulsmenumarche");
		var ulInnovations = document.getElementById("ulsmenuinnovations");
		var ulActualites = document.getElementById("ulsmenuactualites");
		var ulDossier = document.getElementById("ulsmenudossiers");
		var ulPodcasts = document.getElementById("ulsmenupodcast");
		
		overMenu( navRoot );
		overMenu( ulUsages );
		overMenu( ulMarche );
		overMenu( ulInnovations );
		overMenu( ulActualites );
		overMenu( ulDossier );
		overMenu( ulPodcasts );
		reSizeSousSousMenu( ulUsages );
		reSizeSousSousMenu( ulMarche );
		reSizeSousSousMenu( ulInnovations );
		reSizeSousSousMenu( ulActualites );
		reSizeSousSousMenu( ulDossier );
		reSizeSousSousMenu( ulPodcasts );
	}
}

window.onresize = function()
{
	if (document.all&&document.getElementById)
	{
		reSizeSousMenu();
		
		var ulUsages = document.getElementById("ulsmenuusages");
		var ulMarche = document.getElementById("ulsmenumarche");
		var ulInnovations = document.getElementById("ulsmenuinnovations");
		var ulActualites = document.getElementById("ulsmenuactualites");
		var ulDossier = document.getElementById("ulsmenudossiers");
		var ulPodcasts = document.getElementById("ulsmenupodcast");
		
		reSizeSousSousMenu( ulUsages );
		reSizeSousSousMenu( ulMarche );
		reSizeSousSousMenu( ulInnovations );
		reSizeSousSousMenu( ulActualites );
		reSizeSousSousMenu( ulDossier );
		reSizeSousSousMenu( ulPodcasts );
	}
}

function debug(str)
{
	var debug = document.getElementById("debug");
	debug.innerHTML = debug.innerHTML+"<br />"+str;
}

function reSizeSousMenu()
{
	if (document.all&&document.getElementById)
	{
		var navRoot = document.getElementById("nav2");
		var ulUsages = document.getElementById("ulsmenuusages");
		ulUsages.style.width = navRoot.offsetWidth+"px";
		var ulMarche = document.getElementById("ulsmenumarche");
		ulMarche.style.width = navRoot.offsetWidth+"px";
		var ulInnovations = document.getElementById("ulsmenuinnovations");
		ulInnovations.style.width = navRoot.offsetWidth+"px";
		var ulActualites = document.getElementById("ulsmenuactualites");
		ulActualites.style.width = navRoot.offsetWidth+"px";
		var ulDossier = document.getElementById("ulsmenudossiers");
		ulDossier.style.width = navRoot.offsetWidth+"px";
		var ulPodcasts = document.getElementById("ulsmenupodcast");
		ulPodcasts.style.width = navRoot.offsetWidth+"px";
	}
}

function reSizeSousSousMenu( nodeParent )
{
	if (document.all&&document.getElementById)
	{
		var navRoot = document.getElementById("nav2");
		for (var i=0; i<nodeParent.childNodes.length; i++)
		{
			var node = nodeParent.childNodes[i];
			if (node.nodeName=="LI")
			{
				for (var j=0; j<node.childNodes.length; j++)
				{
					var nodeSousMenu = node.childNodes[j];
					if (nodeSousMenu.nodeName=="UL")
					{
						nodeSousMenu.style.width = navRoot.offsetWidth+"px";
					}
				}
			}
		}
	}
}

function overMenu( nodeParent )
{
	if (document.all&&document.getElementById)
	{
		for (var i=0; i<nodeParent.childNodes.length; i++)
		{
			node = nodeParent.childNodes[i];
			if (node.nodeName=="LI")
			{
				node.onmouseover=function()
				{
					className = this.className;
					this.className += " over";
					if( this.className == "lioff2 over" ){
						this.className += ' nardin';
					}
				}
				node.onmouseout=function()
				{
					this.className=this.className.replace(" over", "");
					if( this.className == "lioff2 nardin" ){
						this.className=this.className.replace(" nardin", "");
					}
				}
			}
		}
	}
}

var getMouse = function (e)
	{
		var pos = new Array();
	
		if (!e) var e = window.event;
	
		if (e.pageX || e.pageY)
		{
			pos['x'] = e.pageX;
			pos['y'] = e.pageY;
		}
		else if (e.clientX || e.clientY)
		{
			pos['x'] = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			pos['y'] = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}
		
		return pos;
	}

	var getMouseY = function (e)
	{
		var pos = getMouse(e);
		return pos['y'];
	}