var agent = navigator.userAgent.toLowerCase();
var w3c = document.getElementById ? true : false;
var iex = (navigator.appName == 'Microsoft Internet Explorer') ? true : false;
function getStyle(nom){
	return w3c ? document.getElementById(nom).style : iex ? document.all[nom].style : false;
}
function getObj(nom){
	return w3c ? document.getElementById(nom) : iex ? document.all[nom] : false;
}
Menu = function(nom, parent){
	this.name = nom;
	this.timer = null;
	this.parent = parent;
	this.obj = nom+'Object';
	eval(this.obj+'=this');
}
Menu.prototype.montrer = function(nomSubMenu){
	hideSibling(this.name);
	menuCourant = this.name;
	objMenuCourant = getStyle(this.name);
	objDysplayMenu = getObj(nomSubMenu);
	clearTimeout(this.timer);
	var windowWidth = iex ? document.body.clientWidth : window.innerWidth;
	var offset = Math.floor((windowWidth-770)/2);
	if(offset < 0){
		offset = 0;
	}
	var psoitionHaut = objDysplayMenu.offsetTop ? (objDysplayMenu.offsetTop + objDysplayMenu.offsetHeight + 1): 203;;
	var psoitionGauche = objDysplayMenu.offsetLeft;
	if (psoitionGauche == 0) {
	 if (objDysplayMenu.offsetParent.offsetParent.offsetLeft == 0) { // opera
	 	psoitionGauche = objDysplayMenu.offsetParent.offsetLeft;
		psoitionHaut = objDysplayMenu.offsetParent.offsetTop+objDysplayMenu.offsetParent.offsetHeight+6;
	 } else { //konqueror + ie
	 	psoitionGauche = objDysplayMenu.offsetParent.offsetLeft+offset;
		psoitionHaut = iex ? 205 : 218;
	 }
	}
	if (this.parent != null) {
		psoitionGauche += getObj(this.parent).clientWidth + 3;
		psoitionHaut = getObj(this.parent).offsetTop + getObj(nomSubMenu).offsetTop;
	}
	objMenuCourant.left = psoitionGauche+"px";
	objMenuCourant.top = psoitionHaut+"px";
	objMenuCourant.visibility = 'visible';
}

Menu.prototype.cacher = function(){
	this.timer = setTimeout(this.obj+'.cacheLe()',300);
}
Menu.prototype.cacheLe = function(){
	if (!hasVisibleChild(this.name)) {
		getStyle(this.name).visibility = 'hidden';
		if (menuTarget != this.parent && isVisible(this.parent)) {
			setTimeout(Menus[this.parent].obj + '.cacheLe()', 10)
		}
	}
}
cacheLes = function(){
	if(menuCourant != null){
		Menus[menuCourant].cacheLe();
		menuCourant = null;
	}
}
creerMenu = function(nom, parent){
	Menus[nom] = new Menu(nom, parent);
}

isVisible = function(nom) {
	if (nom != null) {
		return getStyle(nom).visibility == 'visible';
	}
	return false;
}

hasVisibleChild = function(nom) {
	for (var p in Menus) {
		if (Menus[p].parent == nom && getStyle(p).visibility == 'visible') {
			return true;
		}
	}
	return false;
}

hideSibling = function(nom) {
	for (var p in Menus) {
		if (p != nom && Menus[p].parent == Menus[nom].parent && getStyle(p).visibility == 'visible'){
			getStyle(p).visibility = 'hidden';
		}
	}
}

updateTarget = function(nom) {
	menuTarget = nom;
}

Menus = new Object();
var menuCourant = null;
var menuTarget = null;
