/* **************************************
**
**		Scripts Statistique
**		David Fraga
**		maj : 04-11-2010
**
****************************************/


// Ouverture de l'onglet (div) associé à l'ancre présente dans le lien
function divOpen() { 
	numAncre=window.location.hash;
	
		if(numAncre!=""){		
			numAncre=numAncre.substring(1);
			//alert(numAncre);
				for (var i = 1; i<=100; i++) {
					if (document.getElementById("texte"+i)) {document.getElementById("texte"+i).style.display="none";}
				}
			document.getElementById("texte"+numAncre).style.display="block";
			//return showDiv('texte'+numAncre);
		}else{
			showDiv();
		}
    } 
window.onload = divOpen; 



/*************************************************
**			News slider	DAF						**
**			M-A-J : 24-02-2010					**
*************************************************/

// Initialisation variables
Nom = navigator.appName;
Version = navigator.appVersion;
Version = Version.substring(21,23);
ie6 = (Nom == 'Microsoft Internet Explorer' && Version == 6 ) ? 1:0
actuActive=0
nbreActus=3

// On affiche aléatoirement l'une des actus avec ses styles
function randomActu(){
	var numActu=Math.ceil(Math.random()*nbreActus);
	var nomImageActu=document.getElementById("titre_"+numActu).onmouseover+"";
	nomImageActu=nomImageActu.substring(nomImageActu.indexOf("changeOver(",1)+12,nomImageActu.indexOf(");",1)-6);

	document.getElementById("newsslider").style.backgroundImage = 'url('+nomImageActu+')';
	document.getElementById("titre_"+numActu).style.borderLeft = '6px solid #3d88a1';
	document.getElementById("titre_"+numActu).style.backgroundColor = '#f9f9f9';

	document.getElementById("actuLien_"+numActu).style.color = '#3D88A1';
	document.getElementById("fleche_"+numActu).src="/statistique/images/actualite/fleche.png";
	if (ie6) {
		document.getElementById("fleche_"+numActu).src="/statistique/images/actualite/fleche.gif";
	}
}


// On affiche l'image et les styles en fonction de l'actu survolée
function changeOver(urlImage,idActu){
	if(actuActive!=idActu){
		for (i=1; i<=nbreActus; i++){
			document.getElementById("titre_"+i).style.borderLeft = '6px solid #d0d0d0';
			document.getElementById("titre_"+i).style.backgroundColor = 'white';
			document.getElementById("actuLien_"+i).style.color = '#666';
			document.getElementById("fleche_"+i).src="/statistique/images/actualite/vide.gif";
  		 } 

		document.getElementById("newsslider").style.backgroundImage = 'url('+urlImage+')';
		document.getElementById("titre_"+idActu).style.borderLeft = '6px solid #3d88a1';
		document.getElementById("titre_"+idActu).style.backgroundColor = '#f9f9f9';
		document.getElementById("actuLien_"+idActu).style.color = '#3D88A1';		
		document.getElementById("fleche_"+idActu).src="/statistique/images/actualite/fleche.png";
		if (ie6) {
			document.getElementById("fleche_"+idActu).src="/statistique/images/actualite/fleche.gif";
		}
		actuActive=idActu;
	}
}


/*************************************************
**			Menu déroulant						**
**			Modifié par DAF						**
**			M-A-J : 09-02-2011					**
*************************************************/
var initialisation =0;
var nomIdGlob="";
var xb =
{
	evtHash: [],

	ieGetUniqueID: function(_elem)
	{
		if (_elem === window) { return 'theWindow'; }
		else if (_elem === document) { return 'theDocument'; }
		else { return _elem.uniqueID; }
	},

	addEvent: function(_elem, _evtName, _fn, _useCapture)
	{
		if (typeof _elem.addEventListener != 'undefined')
		{
			if (_evtName == 'mouseenter')
				{ _elem.addEventListener('mouseover', xb.mouseEnter(_fn), _useCapture); }
			else if (_evtName == 'mouseleave')
				{ _elem.addEventListener('mouseout', xb.mouseEnter(_fn), _useCapture); } 
			else
				{ _elem.addEventListener(_evtName, _fn, _useCapture); }
		}
		else if (typeof _elem.attachEvent != 'undefined')
		{
			var key = '{FNKEY::obj_' + xb.ieGetUniqueID(_elem) + '::evt_' + _evtName + '::fn_' + _fn + '}';
			var f = xb.evtHash[key];
			if (typeof f != 'undefined')
				{ return; }
			
			f = function()
			{
				_fn.call(_elem);
			};
		
			xb.evtHash[key] = f;
			_elem.attachEvent('on' + _evtName, f);
	
			// attach unload event to the window to clean up possibly IE memory leaks
			window.attachEvent('onunload', function()
			{
				_elem.detachEvent('on' + _evtName, f);
			});
		
			key = null;
			//f = null;   /* DON'T null this out, or we won't be able to detach it */
		}
		else
			{ _elem['on' + _evtName] = _fn; }
	},	

	removeEvent: function(_elem, _evtName, _fn, _useCapture)
	{
		if (typeof _elem.removeEventListener != 'undefined')
			{ _elem.removeEventListener(_evtName, _fn, _useCapture); }
		else if (typeof _elem.detachEvent != 'undefined')
		{
			var key = '{FNKEY::obj_' + xb.ieGetUniqueID(_elem) + '::evt' + _evtName + '::fn_' + _fn + '}';
			var f = xb.evtHash[key];
			if (typeof f != 'undefined')
			{
				_elem.detachEvent('on' + _evtName, f);
				delete xb.evtHash[key];
			}
		
			key = null;
			//f = null;   /* DON'T null this out, or we won't be able to detach it */
		}
	},
	
	mouseEnter: function(_pFn)
	{
		return function(_evt)
		{
			var relTarget = _evt.relatedTarget;				
			if (this == relTarget || xb.isAChildOf(this, relTarget))
				{ return; }

			_pFn.call(this, _evt);
		}
	},
	
	isAChildOf: function(_parent, _child)
	{
		if (_parent == _child) { return false };
		
		while (_child && _child != _parent)
			{ _child = _child.parentNode; }
		
		return _child == _parent;
	}	
};
var tempo="";
function temporisation(nomId) {
		nomId.style.display='none';
		nomId.style.display='';
		
		clearTimeout(tempo);	
}

function initMenu(thisId,initialis,initialTop){
	//alert(thisId.hasChildNodes());
	//alert(thisId.getElementsByTagName('ul')[0].id);
	
	
	
					//on ferme les éventuels menus ouverts
				if ((nomIdGlob!="")&&(nomIdGlob!=thisId)){
					nomIdGlob.style.display='none';
					nomIdGlob.style.display='';
					}
					
					//on gère la hauteur du menu, si besoin
					if (initialTop!=""){
					thisId.getElementsByTagName('ul')[0].style.top=initialTop;
					}
	
	
		if(initialisation==0){
			//alert("testDAF");
				initialisation=1;
				nomIdGlob=thisId;
				var theList = thisId;
				xb.addEvent(theList, 'mouseenter', enter, false);
				xb.addEvent(theList, 'mouseleave', leave, false);
			
			}
}
			
			function enter(e)
			{

				
				
				nomId=this.id;
				this.style.display='block';
				this.style.display='';				
				clearTimeout(tempo);
				//alert("test DAF");
			}
			
			function leave(e)
			{
				//alert("On quitte");
				//alert(this.getElementsByTagName('ul')[0].title);
				nomId=this.getElementsByTagName('ul')[0];
				nomIdGlob=this.getElementsByTagName('ul')[0];
				//nomId='niveau2';
				nomId.style.display='block';
				initialisation=0;
				tempo = setTimeout("temporisation(nomId)",500);
			}
			









