loader = window;
loader.onload = startIt;
isLoaded = false;
areCreated = false;
menuLoc = null;
decalagex = 0;
decalagey = 21;

function initVars() {
	if(areCreated) {
		for(i=1; i<topCount; i++) {
			cur = eval("Menu"+i);
			clearTimeout(cur.hideTimer);
			cur.hideTimer=null;
		}
		clearTimeout(allTimer);
	}
	topCount = 1;
	areCreated = false;
	beingCreated = false;
	isOverMenu = false;
	currentMenu = null;
	allTimer = null;
}
initVars();

function IEunloaded() {
	initVars();
	isLoaded = false;
	setTimeout("keepTrack()",50)
}

function keepTrack() {
	if (menuLoc.document.readyState == "complete") {
		initVars();
		startIt();
	}
	else {
		setTimeout("keepTrack()",50);
	}
}

function startIt() {
	isLoaded = true;
	menuLoc = window;
	menuLoc.nav = nav = window;
	makeTop();	
}

function makeTop(){
	beingCreated = true;
	while(eval("window.MenuContenu" + topCount)) {
		makeMenuIE(false,topCount);
		topCount++
	}
	areCreated = true;
	beingCreated = false;
}



function makeMenuIE(isChild,menuCount,parMenu) {
	menu = makeElement("Menu" + menuCount);
	menu.array = eval("MenuContenu" + menuCount);
	menu.setMenuTree = setMenuTree;
	menu.setMenuTree(isChild,parMenu);
	menu.itemStr = "";
	while (menu.itemCount < menu.maxItems) {
		menu.itemCount++;
		itemName = "item" + menuCount + "_" + menu.itemCount;
		arrayPointer = ((menu.itemCount-1)*4);
		dispText = menu.array[arrayPointer];
		hasMore = menu.array[arrayPointer + 2];
		titre = menu.array[arrayPointer + 4];
		htmStr = (hasMore) ? dispText : dispText;
		menu.itemStr += "<SPAN ID=" + itemName + " STYLE=\"width:190;font-size:7pt\">&nbsp;&nbsp;" + htmStr + "</SPAN><BR>";
		
		if (hasMore) {
			makeMenuIE(true,menuCount + "_" + menu.itemCount,menu);
			menu = menu.parentMenu;
		}	
	}

	menu.innerHTML = menu.itemStr;
	itemColl = menu.children.tags("SPAN");
	for (i=0; i<itemColl.length; i++) {
		it = itemColl(i);
		it.setup = itemSetup;
		it.setup(i+1,menu.array);
	}
	menu.lastItem = itemColl(itemColl.length-1);
	menu.setup(isChild,parMenu);
}

function makeElement(whichEl,whichWidth,whichParent,whichContainer) {
	elStr = "<DIV ID=" + whichEl + " STYLE='position:absolute'></DIV>";
	menuLoc.document.body.insertAdjacentHTML("BeforeEnd",elStr);
	return eval(whichEl);
}

function itemSetup(whichItem,whichArray) {
	this.onmouseover = itemOver;
	this.onmouseout = itemOut;
	this.container = this.offsetParent;
	arrayPointer = (this.container.hasParent) ? (whichItem-1)*4 : ((whichItem-1)*4);
	this.dispText = whichArray[arrayPointer];
	this.Adresse = whichArray[arrayPointer + 1];
	this.hasMore = whichArray[arrayPointer + 2];
	this.cat = whichArray[arrayPointer + 3];
	this.titre = whichArray[arrayPointer + 4];
	if (this.hasMore) {
		this.child = eval("Menu" + this.id.substr(4));
		this.child.parentMenu = this.container;
		this.child.parentItem = this;
	}
	if (this.Adresse) {
			this.onclick = linkIt;
			this.style.cursor = "hand";					
	}
	
	with (this.style) {
		padding = 1;
		if (this.Adresse) {
		color = this.container.menuFontColor;
						}
						else
						{
		color = this.container.TitreFontColor;
						}
		fontSize = "10 px";
		fontWeight = "bold";
		fontStyle =	"normal";
		fontFamily = "Verdana, Helvetica, Arial";
		backgroundColor = this.container.menuBGColor;
	}
}	

function menuSetup(hasParent,openCont,openItem) {
	this.onmouseover = menuOver;
	this.onmouseout = menuOut;
	this.showIt = showIt;
	this.hideTree = hideTree
	this.hideParents = hideParents;
	this.hideTop = hideTop;
	this.isOn = false;
	this.hideTimer = null;
	this.currentItem = null;
	this.hideSelf = hideSelf;
	this.hasParent = false;

	with (this.style) {
		width = this.menuWidth;
		borderWidth = 1;
		borderColor = this.menuBorCol;
		borderStyle = "solid";
	}
	this.lastItem.style.border="";
	this.fullHeight = this.scrollHeight;
	this.showIt(false);
	this.onselectstart = cancelSelect;
	this.moveTo = moveTo;
	this.moveTo(0,0);
}

function popUp(menuName,e,numlay){
	if (!isLoaded) return;
	linkEl = event.srcElement;
	if (!beingCreated && !areCreated) startIt();
	linkEl.menuName = menuName;	
	popMenu(e,numlay);
}

function getRealLeft() {
	xPos = this.offsetLeft;
    tempEl = this.offsetParent;    
	while (tempEl != null) {
        xPos += tempEl.offsetLeft;        
		tempEl = tempEl.offsetParent;    }
    return xPos;
}
	
function getTrueX() {
	linkEl.getRealLeft = getRealLeft;
	trueX = (linkEl.getRealLeft() + decalagex);
	return trueX;
}

function getRealTop() {    
	yPos = this.offsetTop;    
	tempEl = this.offsetParent;
    while (tempEl != null) {        
		yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;    }    
	return yPos;
}

function getTrueY() {
	linkEl.getRealTop = getRealTop;
	trueY = (linkEl.getRealTop() + decalagey);
	return trueY;

}

function popMenu(e,numlay){
	if (!isLoaded || !areCreated) return true;
	eType = event.type;
	hideAll();
	linkEl = event.srcElement;
	currentMenu = eval(linkEl.menuName);
	currentMenu.hasParent = false;
	currentMenu.treeParent.startChild = currentMenu;
	linkEl.getRealTop = getRealTop;
	menuLocBod = menuLoc.document;
//	yPos = 30;
	yPos = getTrueY();
	xPos = getTrueX();
	currentMenu.moveTo(xPos,yPos);
	currentMenu.isOn = true;
	currentMenu.showIt(true); 
	return false;
}

function menuOver(e) {
	this.isOn = true;
	isOverMenu = true;
	currentMenu = this;
	if (this.hideTimer) clearTimeout(this.hideTimer);
}

function menuOut() {
	theEvent = menuLoc.event;
	if (theEvent.srcElement.contains(theEvent.toElement)) return;
	this.isOn = false;
	isOverMenu = false;
	allTimer = setTimeout("currentMenu.hideTree()",10);  
}

function itemOver(){
	theEvent = menuLoc.event;
	if (theEvent.srcElement.tagName == "IMG") return;	
	if (this.Adresse) {
		this.style.color = this.container.menuFontOver;
		this.style.backgroundColor = this.container.menuBGOver;
				}
				else
				{
		this.style.color = this.container.TitreFontColor;	
				}
	this.container.currentItem = this;
}

function itemOut() {
	theEvent = menuLoc.event;
   	if (theEvent.srcElement.contains(theEvent.toElement)
     || (theEvent.fromElement.tagName=="IMG" && theEvent.toElement.contains(theEvent.fromElement)))
       return;
	this.style.backgroundColor = this.container.menuBGColor;
	if (this.Adresse) {
		this.style.color = this.container.menuFontColor;
				}
				else
				{
		this.style.color = this.container.TitreFontColor;	
				}
}

function moveTo(xPos,yPos) {
	this.style.pixelLeft = xPos;
	this.style.pixelTop = yPos;
}

function showIt(on) {
	this.style.visibility = (on) ? "visible" : "hidden";
	this.currentItem = null;
}

function linkIt() {
		url(this.Adresse);
}

function popDown(menuName){
	if (!isLoaded || !areCreated) return;
	whichEl = eval(menuName);
	whichEl.isOn = false;
	whichEl.hideTop();
}

function hideAll() {
	for(i=1; i<topCount; i++) {
		temp = eval("Menu" + i + ".startChild");
		temp.isOn = false;
		temp.showIt(false);
	}	
}

function hideTree() { 
	allTimer = null;
	if (isOverMenu) return;
	this.hideParents();
}

function hideTop() {
	whichEl = this;
	(this.hideTimer = setTimeout("whichEl.hideSelf()",0));
}

function hideSelf() {
	this.hideTimer = null;
	if (!this.isOn && !isOverMenu) { 
		this.showIt(false);
	}
}

function hideParents() {
	tempMenu = this;
	while (tempMenu.hasParent) {
		tempMenu.showIt(false);
		tempMenu.parentMenu.isOn = false;		
		tempMenu = tempMenu.parentMenu;
	}
	tempMenu.hideTop();
}


function cancelSelect(){return false}

function reDo(){
	if (loader.innerWidth==origWidth && loader.innerHeight==origHeight) return;
	initVars();
	menuLoc.location.reload();
}


