// JavaScript Document
// ################ Préchargement ##############
img_puce = new Image();
img_puce.src = "http://"+location.host+location.pathname+"content/image/puce-white.gif";

// ################# NAVIGATEUR ###############
var isExplorer = (navigator.appName == "Microsoft Internet Explorer");
var isOpera = (navigator.appName == "Opera");
var isFirefox = ((navigator.appName == "Netscape") && (navigator.vendor==""));
var isSafari = ((navigator.appName == "Netscape") && (navigator.navigator.vendor=="Apple Computer, Inc."));

var noMenu = ((isFirefox && (navigator.productSub < "20040000")) || (isExplorer && (navigator.platform == "MacPPC")));

//alert(navigator.vendor);
//alert(navigator.appName);
//alert(navigator.product);
//alert(navigator.platform);
//alert(navigator.productSub);

// ############# AFFICHAGE DES MENUS ############
function show_menu(name_title) {
	if (noMenu) return;
	
	elt_title = document.getElementById(name_title);
	postitle = findPosMenu(elt_title);
	
	elt_menu = document.getElementById("menu_"+name_title);
	elt_menu.style.left = postitle[0]+"px";
	elt_menu.style.top = postitle[1]+getOffsetHeight(elt_title)+"px";
	elt_menu.style.visibility="visible";
	elt_menu.style.height="auto";
	
	// Bug opera : simule un tableau plus grand
	if (isOpera) elt_menu.style.marginBottom = "400px";
}

function show_submenu(name_title) {
	elt_title = document.getElementById(name_title);
	postitle = findPosSubMenu(elt_title);
	postitlescr = findCoord(elt_title);
	
	elt_menu = document.getElementById("menu_"+name_title);
	
	// Selon la position à l'écran
	if (postitlescr[0]+getOffsetWidth(elt_title)+getOffsetWidth(elt_menu) < getClientWidth())
		 elt_menu.style.left = postitle[0]+getOffsetWidth(elt_title)-4+"px"; 
	else elt_menu.style.left = postitle[0]-getOffsetWidth(elt_menu)+4+"px";
		
	elt_menu.style.top = postitle[1]+"px";
	
	elt_menu.style.visibility="visible";
	elt_menu.style.height="auto";
	
	// Fond eclaire
	eltmenu_on(name_title);
}

function hide_menu(name_title) {
	elt_menu = document.getElementById("menu_"+name_title);
	elt_menu.style.visibility="hidden";
	elt_menu.style.height="0px";
	
	// Fond normal
	eltmenu_off(name_title);
}

// ################# FOND DE MENU ###############
function changeBackgroundColor(elt, active) {
	if (active) elt.style.backgroundColor="#EE0000";
	else elt.style.backgroundColor="#CC0000";
}

function eltmenu_on(name_title) {
	elt_title = document.getElementById(name_title);
	
	// Pas menu primaire ?
	if (elt_title.nodeName != "SPAN")
		changeBackgroundColor(elt_title, true);
}

function eltmenu_off(name_title) {
	elt_title = document.getElementById(name_title);
	
	// Pas menu primaire ?
	if (elt_title.nodeName != "SPAN")
		changeBackgroundColor(elt_title, false);
}

// ############### COORDONNEES ###############
function findPosMenu(obj) {
	var curleft = curtop = 0;
	
	while(obj) {
		//alert(obj.nodeName+"(id:"+obj.id+";left:"+getOffsetLeft(obj)+";top:"+getOffsetTop(obj)+")");
		
		// Spécifique navigateur
		if (isExplorer || isOpera || isSafari) {
			if (obj.id == "header") break;
		}
		
		curleft+= getOffsetLeft(obj);
		curtop += getOffsetTop(obj);
		
		obj = obj.offsetParent;
	}
	
	return [curleft,curtop];
}

function findPosSubMenu(obj) {
	var curleft = curtop = 0;

	while(obj) {
		//alert(obj.nodeName+"(id:"+obj.id+";left:"+getOffsetLeft(obj)+";top:"+getOffsetTop(obj)+")");
		
		// Spécifique navigateur
		if (isExplorer || isSafari) {
			if (obj.id.substr(0, 10) == "menu_title") break;
		}
		
		if (isOpera) {
			if (obj.id.substr(0, 10) == "menu_title") {
				curleft+= getOffsetLeft(obj);
				break;
			}
		}
				
		curleft+= getOffsetLeft(obj);
		curtop += getOffsetTop(obj);
				
		obj = obj.offsetParent;
	}
	
	return [curleft,curtop];
}

function findCoord(obj) {
	var curleft = curtop = 0;
	
	while(obj) {
		//alert(obj.nodeName+"(id:"+obj.id+";left:"+getOffsetLeft(obj)+";top:"+getOffsetTop(obj)+")");
		
		// Spécifique navigateur
		if (isExplorer || isOpera || isSafari) {
			if (obj.id == "header") break;
		}
		
		// Opera gère mal les TR ...
		if (!isOpera || obj.nodeName != "TR") {
			curleft+= getOffsetLeft(obj);
			curtop += getOffsetTop(obj);
		}
		
		obj = obj.offsetParent;
	}
	
	return [curleft,curtop];
}

function getClientWidth() {
	if (isOpera) return document.getElementById("header").offsetWidth; 
	else return document.body.clientWidth;
}

// ############ POSITION : POUR BUG SAFARI ############
function getOffsetWidth(elt) {
	// Special bug safari 
	if (isSafari && elt.nodeName=="TR") return elt.lastChild.offsetLeft+elt.lastChild.offsetWidth;
	else return elt.offsetWidth;
}

function getOffsetHeight(elt) {
	return elt.offsetHeight;
}

function getOffsetLeft(elt) {
	return elt.offsetLeft;
}

function getOffsetTop(elt) {
	// Special bug safari 
	if (isSafari && elt.nodeName=="TR") return elt.lastChild.offsetTop;
	else return elt.offsetTop;
}