<!-- ---------------------------------------------------- -->
<!-- Menu Bar Demo                                        -->
<!--                                                      -->
<!-- Copyright 2000 by Mike Hall                          -->
<!-- Please see http://www.brainjar.com for terms of use. -->
<!-- ---------------------------------------------------- -->
// Determine browser and version.

function Browser() {
  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}



var browser = new Browser();

// Global variable for tracking the currently active item.
var activeItem = null;
var activeSubItem = null;

// Capture mouse clicks on the page so any active item can be
// deactivated.

if (browser.isIE)
  document.onmousedown = pageMousedown;
if (browser.isNS)
  document.addEventListener("mousedown", pageMousedown, true);



function pageMousedown(event) {
  	var el;
	
  	// If there is no active menu, exit.
  	if (!activeItem)
    	return;

  	// Find the element that was clicked on.
  	if (browser.isIE)
    	el = window.event.srcElement;
  	if (browser.isNS)
    	el = (event.target.className ? event.target : event.target.parentNode);
	
  	// If the active item was clicked on, exit.
  	if (el == activeItem)
    	return;
	
  	// If the element clicked on was not a menu item or item, close the
  	// active menu.	
  	if (el.className != "menu" && el.className != "menuItem" && el.className != "menuItemMoyen" && el.className != "menuItemLong" && el.className != "subMenuItem" && el.className != "subSubMenuItem" && el.className != "subMenuItemActive"){
    	resetItems();
	}
	
	//Reset all other buttons to initial color
  setColorOfLinksBack("#938F82");
	
	return;
}



function itemMouseover(button, menuName) {
	if(activeItem == button) return;
	
  // Blur focus from the link to remove that annoying outline.
  button.blur();

  // Associate the named menu to this item if not already done.
  if (!button.menu)
    button.menu = document.getElementById(menuName);

  // Reset the currently active item, if any.
  if (activeItem && activeItem != button)
    resetItems();

  // Toggle the item's state.
  if (button.isDepressed)
    resetItems();
  else
    depressItem(button);
  
  //Reset all other buttons to initial color
  setColorOfLinksBack("#938F82");
  
  //Set color of active button to white
  button.getElementsByTagName('A')[0].style.color = "#FFFFFF";
  

  return false;
}

function setColorOfLinksBack(color){
	//First set color of others to the old one
	var btns = getElementsByClassName("menuItem");
	for(i=0;i<btns.length;i++){
		btns[i].getElementsByTagName('A')[0].style.color = "#938F82";
	}
	var btns2 = getElementsByClassName("menuItemLong");
	for(i=0;i<btns2.length;i++){
		btns2[i].getElementsByTagName('A')[0].style.color = "#938F82";
	}
	var btns3 = getElementsByClassName("menuItemMoyen");
	for(i=0;i<btns3.length;i++){
		btns3[i].getElementsByTagName('A')[0].style.color = "#938F82";
	}
	
	document.getElementById("menuItemUrgences").getElementsByTagName('A')[0].style.color = "#BD2C16";
}



function subItemMouseover(button, menuName) {
	if(activeSubItem == button) return;
	
  // Blur focus from the link to remove that annoying outline.
  button.blur();

  // Associate the named menu to this button if not already done.
  if (!button.menu)
    button.menu = document.getElementById(menuName);
  if(button.menu == null){
  	resetSubItem();
	return false;
  }

  // Reset the currently active button, if any.
  if (activeSubItem && activeSubItem != button)
    resetSubItem(activeSubItem);

  // Toggle the button's state.
  if (button.isDepressed)
    resetSubItem(button);
  else
    depressSubItem(button);

  return false;
}


function depressItem(button) {

  var w, dw, x, y;

  // Change the button's style class to make it look like it's depressed.
  if(button.className == "menuItemLong")
  	button.className = "menuItemLongActive";
  else if(button.className == "menuItemMoyen")
  	button.className = "menuItemMoyenActive";
  else
  	button.className = "menuItemActive";
  
  // For IE, set an explicit width on the first menu item. This will
  // cause link hovers to work on all the menu's items even when the
  // cursor is not over the link's text.
  if (browser.isIE && button.menu != null && !button.menu.firstChild.style.width) {
    w = button.menu.firstChild.offsetWidth;
    button.menu.firstChild.style.width = w + "px";
    dw = button.menu.firstChild.offsetWidth - w;
    w -= dw;
    button.menu.firstChild.style.width = w + "px";
  }

  // Position the associated drop down menu under the button and
  // show it. Note that the position must be adjusted according to
  // browser, styling and positioning.

  x = button.offsetLeft;
  y = getPageOffsetTop(button)-20;
  
  if (browser.isNS && browser.version < 6.1)
    y--;

  // Position and show the menu.
  if(button.menu != null){
  	button.menu.style.left = x + "px";
  	button.menu.style.top  = y + "px";
  	button.menu.style.visibility = "visible";
  }

  // Set button state and let the world know which button is
  // active.

  button.isDepressed = true;
  activeItem = button;
}


function depressSubItem(button) {
  // Change the button's style class to make it look like it's depressed.
  button.className = "subMenuItemActive";


  // Position the associated drop down menu under the button and
  // show it. Note that the position must be adjusted according to
  // browser, styling and positioning.  
  var pt=getPageOffset(button);
  pt.y+=button.offsetHeight;
  
  
  if (browser.isIE) {
    pt.x += 1;
  }
  
  // Position and show the menu.
  button.menu.style.left=pt.x+"px";
  button.menu.style.top=pt.y+"px";
  button.menu.style.visibility = "visible";

  // Set button state and let the world know which button is
  // active.
  button.isDepressed = true;
  activeSubItem = button;
}


function resetItems() {
	if(activeSubItem != null){
		// Restore item's style classe.
		activeSubItem.className = "subMenuItem";
		
		// Hide the items's subSubmenu.
		if(activeSubItem.menu)
			activeSubItem.menu.style.visibility = "hidden";
		
		// Set button state and clear active menu global.
		activeSubItem.isDepressed = false;
		activeSubItem = null;
	}
	
	if(activeItem != null){
		// Restore item's style classe.
		//Special for urgences
		if(activeItem.className == "menuItemLongActive")
		 activeItem.className = "menuItemLong";
		else if(activeItem.className == "menuItemMoyenActive")
		 activeItem.className = "menuItemMoyen";
		else if(activeItem.id != "menuItemUrgences")
		 activeItem.className = "menuItem";
		 
		// Hide the items's submenu.
		if (activeItem.menu)
    		activeItem.menu.style.visibility = "hidden";
		
		// Set button state and clear active menu global.
		activeItem.isDepressed = false;
		activeItem = null;
	}
}

function resetSubItem() {
	if(activeSubItem != null){
		// Restore item's style classe.
		activeSubItem.className = "subMenuItem";
		
		// Hide the items's subSubmenu.
		if(activeSubItem.menu)
			activeSubItem.menu.style.visibility = "hidden";
		
		// Set button state and clear active menu global.
		activeSubItem.isDepressed = false;
		activeSubItem = null;
	}
}


function getPageOffsetLeft(el) {
  	// Return the true x coordinate of an element relative to the page.
  	return el.offsetLeft + (el.offsetParent ? getPageOffsetLeft(el.offsetParent) : 0);
}

function getPageOffsetTop(el) {
  	// Return the true y coordinate of an element relative to the page.
  	return el.offsetTop + (el.offsetParent ? getPageOffsetTop(el.offsetParent) : 0);
}



function getPageOffset(el){
	var x=0,y=0;
	tmp_el = el;
	
	do{
		x+=el.offsetLeft;
		y+=el.offsetTop;
		el=el.offsetParent;
	}
	while(el!=null);
	
	//To get the right width, even if the page is not maximised
	x = x-(getClientWidth()-780)/2+tmp_el.offsetWidth+5;
	
	return new Point(x,y-70);
}

function Point(x,y){
	this.x=x;
	this.y=y;
}


function getClientWidth(){
	var viewportwidth;
	 
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined')
		viewportwidth = window.innerWidth;
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
		viewportwidth = document.documentElement.clientWidth;
	
	// older versions of IE
	else
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
	return viewportwidth;
}




/*
	Developed by Robert Nyman, http://www.robertnyman.com
	Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/	
var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};

