var NumRangs = 1;
var MenuRang;
var SclL = 0;
var SclT = 0;
var timer;
var HideTime = 1200;
var IsOver = new Boolean(false);

window.onload = InitMenu;
window.onunload = HideMenu;

function InitMenu()
{
	try
	{
		CheckFLoaded();					
		return;
	}
	catch(err)
	{	return;	}
}

function CreateSousMenu()
{
	try
	{
		if (document.getElementById("vodconteneur")) return;
		var oStyle = document.createElement("DIV");
		oStyle.setAttribute("id","vodconteneur");
		oStyle.setAttribute("innerHTML","&nbsp;");
		oStyle.setAttribute("visibility","hidden");
		document.getElementById("header").appendChild(oStyle);
		for (i=1;i<=NumRangs;i++)
		{
			InsertCSS(i);
			var oDiv = document.createElement("DIV");
			oDiv.setAttribute("id","Vodmenu" + i);
			oStyle.appendChild(oDiv);
		}
		HideMenu(true);
	}
	catch(ex)
	{
		return;
	}
}

function InsertCSS(Index)
{
	var StyleDiv = new String();
	StyleDiv = '{z-index:1000;text-align:left;position:relative;margin:0;width:'+ tbStyles[Index].Width +'px;filter:alpha(opacity='+ (tbStyles[Index].Opacity==''?100:tbStyles[Index].Opacity) +');';
	StyleDiv += 'font-family:'+ tbStyles[Index].Family +';font-size:'+ tbStyles[Index].Size +'px;';
	StyleDiv += tbStyles[Index].Cadre=="true"?'border:2px solid '+ tbStyles[Index].CadreColor +';':'';
	StyleDiv += tbStyles[Index].Shadow=="true"?'filter:progid:DXImageTransform.Microsoft.dropshadow(offX=5,offY=5,color=' + tbStyles[Index].ShadowCol +',positive=true);':'';
	StyleDiv += Index==0?'top:'+ tbStyles[Index].Top +'px;left:'+ tbStyles[Index].Left +'px;}':'}';

	var StyleUl = new String();	
	StyleUl = '{margin:0;padding:0;}';
//	StyleUl += tbStyles[Index].Shadow=="true"?'padding-bottom:4px;padding-right:4px;background-color:'+ tbStyles[Index].ShadowCol +';}':'}';

	var StyleLi = new String();
	StyleLi = '{list-style:none;margin:0;padding:0;';
	StyleLi += tbStyles[Index].Border=="true"?'padding-right:1px;padding-left:1px;padding-bottom:1px;background-color:' + tbStyles[Index].BorderCol + ';}':'}';

	var StyleCheck = new String();
	StyleCheck = '{width:12px;margin-right:0.3em;margin-top:-3px;}';

	var StyleA = new String();
	StyleA = '{overflow:hidden;display:block;text-decoration:none;padding-left:0.3em;padding-top:2px;';
	StyleA += 'font-family:'+ tbStyles[Index].Family +';font-size:'+ tbStyles[Index].Size +'px;';
	StyleA += 'color:' + tbStyles[Index].Col + ';background-color:' + tbStyles[Index].Bg + ';height:' + tbStyles[Index].Height + 'px;';
	StyleA += tbStyles[Index].ColBold=="true"?'font-weight:bold;':'';
	StyleA += tbStyles[Index].ColItalic=="true"?'font-style:italic;':'';
	StyleA += tbStyles[Index].Img!=''?'background-repeat:repeat-x;background-image: url('+ tbStyles[Index].Img +');}':'}';
	
	var StyleAHover = new String();
	StyleAHover = '{background-color:' + tbStyles[Index].BgOv +';color:' + tbStyles[Index].ColOv + ';';
	StyleAHover += 'font-family:'+ tbStyles[Index].FamilyOv +';font-size:'+ tbStyles[Index].SizeOv +'px;';
	StyleAHover += tbStyles[Index].ColBoldOv=="true"?'font-weight:bold;':'';
	StyleAHover += tbStyles[Index].ColItalicOv=="true"?'font-style:italic;}':'}';

//	top=0,left=1,width=2,height=3,font=4,size=5,color=6,bold=7,italic=8,colorover=9,bold=10, italic=11,bg=12
//	bgover=13, Ombre=14, Ombre Color=15, Opacity=16, Border=17, Border Color = 18

	var NewCSS = new String();
	NewCSS = '<style text="text/css">';
	NewCSS += '#Vodmenu' + Index + StyleDiv;
	NewCSS += '#Vodmenu' + Index + ' UL' + StyleUl;
	NewCSS += '#Vodmenu' + Index + ' LI' + StyleLi;
//	NewCSS += '#Vodmenu' + Index + ' INPUT' + StyleCheck;
	NewCSS += '#Vodmenu' + Index + ' A' + StyleA;
	NewCSS += '#Vodmenu' + Index + ' A:HOVER' + StyleAHover;
	NewCSS += "</style>";

	document.getElementById("vodconteneur").innerHTML += NewCSS;
}

function CheckFLoaded()
{
	try
	{		
		if (document)
			CreateSousMenu();
		else
			window.setTimeout("CheckFLoaded()",200)
	}
	catch(err)
	{
		return;
	}
}

function Start()
{
	if (!IsOver) timer = setTimeout("HideMenu(true)",HideTime);
	IsOver = true;
}

function Stop()
{
	try
	{	clearTimeout(timer);
		IsOver = false;
	}
	catch(err)
	{	return;	}
}

function Status(Val)
{
	window.status = Val;
	return true;
}

function ShowMenu(MenuRef)
{
	var ArrayRang = String(MenuRef).split("-");	
	MenuRang = Number(ArrayRang.length);
	if (MenuRang > NumRangs) return;
	var oElement = new String();
	try
	{
		oElement = document.getElementById("Vodmenu" + MenuRang);
		SclL = document.body.scrollLeft;
		SclT = document.body.scrollTop;
	}
	catch(err)
	{
		return;
	}

	if (oElement == null)
	{
		CreateSousMenu();
		oElement = document.getElementById("Vodmenu" + MenuRang);
		SclL = document.body.scrollLeft;
		SclT = document.body.scrollTop;
	}

	var NewInner = new String();
	for (i=0;i<tbMenus.length;i++)
	{
		
		if (MenuRef + "-" + tbMenus[i][4] == tbMenus[i][0])
		{
			ShowRef = tbMenus[i][0];
			libelle = tbMenus[i][1];
			url = tbMenus[i][2];
			url = (url.indexOf("http://",0)==-1)?"http://" + url:url;
			Target = tbMenus[i][2]==""?"":tbMenus[i][6]==0?"_blank":"";
			NewInner += '<li onmouseover="Status(\'' + tbMenus[i][2] + '\');Stop();">';
			NewInner += '<a href="' + url + '" onmouseover="ShowMenu(\'' + ShowRef + '\');return true;" target="' + Target + '" ';
			NewInner += (tbMenus[i][2]==""?'onclick="return false;"':'onclick="Status(\'\');"') + '>';
			NewInner += libelle + '</a></li>';
		}
	}

	HideMenu();
	if (NewInner == "")	return;

	NewInner = "<ul onmouseout='Start();'>" + NewInner + "</ul>";
	oElement.innerHTML = NewInner;

	var NewTop = Number(tbStyles[MenuRang].Top);
	var NewLeft = Number(tbStyles[MenuRang].Left);

	for (i=0;i<MenuRang;i++)
		NewTop += Number(tbStyles[i].Top) + Number(ArrayRang[i]-1) * Number(tbStyles[i].Height);

	for (i=MenuRang-1;i>0;i--)
		NewLeft = Number(NewLeft) + Number(tbStyles[i].Width) + Number(tbStyles[i].Left);

	NewTop += SclT;
	NewLeft += SclL;

	NewTop = NewTop<0?0:NewTop;
	NewLeft = NewLeft<0?0:NewLeft;
	NewTop = -22;
	
	Nom = navigator.appName;
	Version = navigator.appVersion;
	ie6 = (Nom == 'Microsoft Internet Explorer') ? 1:0
	if (ie6)
		NewTop = -43;

	oElement.style.top = NewTop + "px";
	oElement.style.left = NewLeft + "px";
	oElement.style.visibility = "visible";
}

function HideMenu(All)
{
	try
	{
		Status('');
		var ToDown = All?1:MenuRang;
		for (i=NumRangs;i>=ToDown;i--)
			document.getElementById("Vodmenu" + i).style.visibility = "hidden";
	}
	catch(err)
	{	return;	}
}