/***********************************************
* AnyLink Drop Down Menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var menuwidth=165 //default menu width
var scrollwidth=15 //default scroll width
var scrollheight=16 //default scroll height
var scrollerHeight=12 //default scroller height
var scrollfactor=9 //default scroll factor
var menuheight=250 //default menu height
var menubgcolor='#0F0F0F' //menu bgcolor
var disappeardelay=1000 //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="no" //hide menu when user clicks within menu?
var imagepath = "/world/includes/images/"

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all
var saf=(navigator.userAgent.toLowerCase().indexOf("safari")!=-1)
var targetElem = null;

if (ie4||ns6)
	//document.write('<div id="dropmenucontainer" style="visibility:hidden;width:'+(menuwidth)+'px;background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"><div id="upArrow" style="width:'+(menuwidth)+'px;" onMouseDown="scrolling=1; scroller.scrollIt(-1);" onMouseUp="scrolling=0;"><img src="'+imagepath+'upArrow.gif" border="0"></div><div id="dropmenucontent"><div id="dropmenudiv" style="width:'+menuwidth+'px;background-color:'+menubgcolor+'"></div></div><div id="downArrow" style="width:'+(menuwidth)+'px;" onMouseDown="scrolling=1; scroller.scrollIt(1);" onMouseUp="scrolling=0;"><img src="'+imagepath+'downArrow.gif" border="0"></div></div>');
	document.write('<div id="dropmenucontainer" style="visibility:hidden;width:'+(menuwidth)+'px;background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"><div id="scrollcontainer"><div id="upArrow" style="width:'+(scrollwidth)+'px;" onMouseDown="scrolling=1; scroller.scrollIt(-1);" onMouseUp="scrolling=0;"><img src="'+imagepath+'upArrow.gif" border="0"></div><div id="scroll" onClick="scrolling=1; scroller.handleScrollClick(event); scrolling=0;"><div id="scroller"></div></div><div id="downArrow" style="width:'+(scrollwidth)+'px;" onMouseDown="scrolling=1; scroller.scrollIt(1);" onMouseUp="scrolling=0;"><img src="'+imagepath+'downArrow.gif" border="0"></div></div><div id="dropmenucontent"><div id="dropmenudiv" style="width:'+(menuwidth-scrollwidth)+'px;background-color:'+menubgcolor+'"></div></div></div>');

if(ns6) {
	//menuheight -= 1;
}

function dropdownmenu(obj, e, menucontents, menuwidth){
	if (window.event) 
		event.cancelBubble=true;
	else if (e.stopPropagation) 
		e.stopPropagation();
	
	clearhidemenu();
	
	//On annule l'événement si c'est le même target
	if (!validateTarget(targetElem,ie4?e.srcElement:e.target) && document.getElementById("dropmenucontainer").style.visibility=="visible") return false;
	
	dropmenuobj = document.getElementById("dropmenucontainer");
	dropmenucont = document.getElementById("dropmenudiv");
	dropmenucontain = document.getElementById("dropmenucontent");
	dropmenuscrollcont = document.getElementById("scrollcontainer");
	dropmenuscroll = document.getElementById("scroll");
	
	dropmenudownarrow = document.getElementById("downArrow");
	dropmenuuparrow = document.getElementById("upArrow");
	
	dropmenuobj.style.height = "";
	dropmenucont.style.height = "";
	dropmenucont.style.top = "";
	dropmenucontain.style.height = "";
	
	populatemenu(menucontents);
	
	if (ie4||ns6){
		if (typeof menuwidth=="string"){
			if(menuwidth.indexOf('px')!=-1) menuwidth = menuwidth.replace('px', '');
			menuwidth = parseInt(menuwidth);
		}
		
		showhide(dropmenuobj.style, e, "visible", "hidden", (menuwidth + ((ie4 && !window.opera) ? 2 : 0)));
		targetElem = obj;
				
		//On ajuste les hauteurs pour setter le scrollbar
		if (dropmenucont.offsetHeight > menuheight) { //dropmenuobj.offsetHeight > menuheight || 
			scroller.init();
			
			dropmenuobj.style.height = menuheight - (window.opera ? 2 : 1);
			dropmenucontain.style.height = menuheight - (ie4 ? 1 : 1);
			dropmenucontain.style.width = menuwidth - scrollwidth - (ie4 ? 0 : 0) - 1;	
			dropmenucont.style.width = menuwidth - scrollwidth - (ie4 ? 0 : 0) - 1;	
			document.getElementById("scroller").style.top = 0;
			
			dropmenuuparrow.style.width = scrollwidth;
			dropmenudownarrow.style.width = scrollwidth;
			dropmenuscroll.style.width = scrollwidth;
			dropmenuscroll.style.height = menuheight - 2 * scrollheight;
			dropmenuscrollcont.style.height = menuheight - (ie4 ? (2 * scrollheight) : 0);
			
			if (dropmenuobj.style.visibility != "hidden") {
				dropmenuuparrow.style.visibility = "visible";
				dropmenuscroll.style.visibility = "visible";
				dropmenudownarrow.style.visibility = "visible";
				dropmenuuparrow.style.display = (ie4 && !window.opera) ? "inline" : "block";
				dropmenuscroll.style.display = (ie4 && !window.opera) ? "inline" : "block";
				dropmenudownarrow.style.display = (ie4 && !window.opera) ? "inline" : "block";
			}
			
		} else {
			if (window.removeEventListener)
				window.removeEventListener('DOMMouseScroll', scroller.wheel, false);
			window.onmousewheel = document.onmousewheel = null;
		
			dropmenuobj.style.height = document.getElementById("dropmenudiv").offsetHeight - 1;
			dropmenucontain.style.height = document.getElementById("dropmenudiv").offsetHeight - 1;
			dropmenucontain.style.width = menuwidth;	
			dropmenucont.style.width = menuwidth;	
			dropmenuscroll.style.width = 0;
			dropmenuscroll.style.height = 0;
			dropmenuscrollcont.style.height = 0;
			dropmenuscroll.style.visibility = "hidden";
			dropmenuuparrow.style.visibility = "hidden";
			dropmenudownarrow.style.visibility = "hidden";
			dropmenuuparrow.style.display = "none";
			dropmenuscroll.style.display = "none";
			dropmenudownarrow.style.display = "none";
		}
	
		if (dropmenuobj.style.visibility != "hidden") {
			dropmenuobj.x = getposOffset(obj, "left");
			dropmenuobj.y = getposOffset(obj, "top");
			dropmenuobj.style.left = dropmenuobj.x - clearbrowseredge(obj, "rightedge");
			dropmenuobj.style.top = dropmenuobj.y - clearbrowseredge(obj, "bottomedge") + obj.offsetHeight;
		}
	}

	return clickreturnvalue();
}
		
function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function showhide(obj, e, visible, hidden, menuwidth){
	if (ie4||ns6)
		dropmenuobj.style.left=dropmenuobj.style.top="-500px";
	if (menuwidth!=0){
		dropmenuobj.style.width = menuwidth;
	}
	var elem = ie4?e.srcElement:e.target;
	if (e.type=="click" && (obj.visibility==hidden || validateTarget(targetElem,ie4?e.srcElement:e.target)) || e.type=="mouseover") {
		obj.visibility = visible;
		document.getElementById("downArrow").style.display = (ie4 && !window.opera) ? "inline" : "block";
		document.getElementById("scroll").style.display = (ie4 && !window.opera) ? "inline" : "block";
		document.getElementById("upArrow").style.display = (ie4 && !window.opera) ? "inline" : "block";
	} else if (e.type=="click"){
		obj.visibility = hidden;
		document.getElementById("downArrow").style.display = "none";
		document.getElementById("scroll").style.display = "none";
		document.getElementById("upArrow").style.display = "none";
		targetElem = null;
	}
}

function validateTarget(target,elem) {
	//On valide si c'est le même target ou un élément enfant du target
	if (target === null) return true;
	if (elem === target) return false;
	for(i=0;i<target.childNodes.length;i++) {
		if (!validateTarget(target.childNodes[i],elem)) return false;
	}
	return true;
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset = 0;
	if (whichedge=="rightedge"){
		var windowedge = (ie4 && !window.opera) ? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15;
		dropmenuobj.contentmeasure = dropmenuobj.offsetWidth;
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
			edgeoffset = dropmenuobj.contentmeasure-obj.offsetWidth;
	} else {
		var topedge = (ie4 && !window.opera) ? iecompattest().scrollTop : window.pageYOffset;
		var windowedge = (ie4 && !window.opera) ? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
		dropmenuobj.contentmeasure = dropmenuobj.offsetHeight;
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
			edgeoffset = dropmenuobj.contentmeasure+obj.offsetHeight;
			if ((dropmenuobj.y-topedge) < dropmenuobj.contentmeasure) //up no good either?
				edgeoffset = dropmenuobj.y+obj.offsetHeight-topedge;
		}
	}
	return edgeoffset;
}

function populatemenu(what){
	if (ie4||ns6)
		document.getElementById("dropmenudiv").innerHTML=what.join("");
}

function clickreturnvalue(){
	/*if (ie4||ns6) 
		return false;
	else */
		return true;
}

function contains_ns6(a, b) {
	while (b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
	return false;
}

function dynamichide(e){
	if (ie4&&!dropmenuobj.contains(e.toElement))
		delayhidemenu();
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		delayhidemenu();
}

function hidemenu(){
	if (typeof dropmenuobj!="undefined"){
		if (ie4||ns6) {
			document.getElementById("dropmenucontainer").style.visibility="hidden";
			document.getElementById("downArrow").style.visibility="hidden";
			document.getElementById("scroll").style.visibility="hidden";
			document.getElementById("upArrow").style.visibility="hidden";
			
			if (window.removeEventListener)
				window.removeEventListener('DOMMouseScroll', scroller.wheel, false);
			window.onmousewheel = document.onmousewheel = null;
		}
	}
}

function delayhidemenu(){
	if (ie4||ns6)
		delayhide=setTimeout("hidemenu()",disappeardelay);
}

function clearhidemenu(){
	if (typeof delayhide!="undefined")
		clearTimeout(delayhide);
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu;

var scroller = {
	obj : null,
	init: function() {
	  //collect the variables
		scroller.docH = dropmenuobj.offsetHeight;
		
		// fixed height
		scroller.scrollDist = menuheight - (2 * scrollheight) - scrollerHeight - ((ie4 && !window.opera)?2:0);
		scroller.contH = menuheight;
		
		//make the scroller div draggable
	  Drag.init(document.getElementById("scroller"),null,0,0,0,scroller.scrollDist);
	    
	   //add ondrag function
	  document.getElementById("scroller").onDrag = function (x,y) {
			docH  = document.getElementById("dropmenudiv").offsetHeight;
			var scrollY = parseInt(document.getElementById("scroller").style.top);
			var docY = 0 - (scrollY * (docH - scroller.contH) / scroller.scrollDist);
			document.getElementById("dropmenudiv").style.top = docY + "px";
		}
		
		if (window.addEventListener)
			window.addEventListener('DOMMouseScroll', scroller.wheel, false);
		window.onmousewheel = document.onmousewheel = scroller.wheel;
   },
		
	//Smooth scrolling
	scrollIt: function (sc) {
		if (scrolling==1) {
			docH = document.getElementById("dropmenudiv").offsetHeight;
			var scrollY = document.getElementById("dropmenudiv").offsetTop;
			
			if (sc > 0 ) { //scroll down
				if (scrollY <= 0) scrollY -= sc * scrollfactor;
				if (scrollY < (-1 * (docH - menuheight))) scrollY = -1 * (docH - menuheight);				
			} else { //scroll up
				if (scrollY < 0) scrollY -= sc * scrollfactor; 
				if (scrollY > 0) scrollY = 0;
			}
			
			document.getElementById("scroller").style.top = (-1 * (scrollY) * (scroller.scrollDist/(docH - scroller.contH))) + "px";
			document.getElementById("dropmenudiv").style.top = scrollY + "px";
			setTimeout("scroller.scrollIt(" + sc +");", 30);
		}
	},
	
	handleScrollClick: function(e) {
		e = scroller.fixE(e);
		if((ie4?e.srcElement:e.target) == document.getElementById("scroller")) return;
		//On vérifie si le click se trouve au dessus ou au dessous du scroller
		var y = parseInt(document.getElementById("scroller").style.top.replace("px", ""));
		if (ns6) {
			if ((e.layerY - e.target.offsetTop) < y) {
				scroller.scrollIt(-1 * menuheight / scrollfactor);
			} else if ((y + scrollerHeight) < (e.layerY - e.target.offsetTop)) {
				scroller.scrollIt(menuheight / scrollfactor);
			}
		} else {
			if ((e.layerY) < y) {
				scroller.scrollIt(-1 * menuheight / scrollfactor);
			} else if ((y + scrollerHeight) < (e.layerY)) {
				scroller.scrollIt(menuheight / scrollfactor);
			}
		}
	},
	
	fixE : function(e) {
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	},
	
	wheel : function (e) {
		var delta = 0;
      e = scroller.fixE(e);
			
      if (e.wheelDelta) { /* IE/Opera. */
         delta = e.wheelDelta / 120;
		} else if (e.detail) { /* Mozilla case. */
			delta = -e.detail / 3;
		}
		
      if (delta)
         scroller.handle(e,delta);
		
		// Prevent default actions caused by mouse wheel. That might be ugly, but we handle scrolls somehow anyway, so don't bother here. 
		if (e.preventDefault)
			e.preventDefault();
		e.returnValue = false;
	},
	
	handle : function(e,delta) {
		scrolling = 1;
		scroller.scrollIt(-delta);
		scrolling = 0;
		return false;
	}
};

function SetCookie(name, value) {
	var expiration = new Date(); 
	expiration.setTime(expiration.getTime() + (100000*1000000));  // 4 years	
	document.cookie = name + "=" + escape(value) + "; path=/; expires=" + expiration.toGMTString() + ";";
}

function GetCookie(name) {

	var cname = name + "=";                
	var dc = document.cookie;              

	if (dc.length > 0) {
		begin = dc.indexOf(cname);        
		if (begin != -1) {
			begin += cname.length;        
			end = dc.indexOf(";", begin); 

			if (end == -1) end = dc.length; 
			return unescape(dc.substring(begin, end)); 
		}  
	} 
	return null; 
}
