﻿if(typeof LOC == 'undefined') {
	var LOC = {};
}
//domloadevent
LOC.addDOMLoadEvent = (function(){
    // create event function stack
    var load_events = [],
        load_timer,
        script,
        done,
        exec,
        old_onload,
        init = function () {
            done = true;
            // kill the timer
            clearInterval(load_timer);
            // execute each function in the stack in the order they were added
            while (exec = load_events.shift())
                exec();
            if (script) script.onreadystatechange = '';
        };
    return function (func) {
        // if the init function was already ran, just run this function now and stop
        if (done) return func();
        if (!load_events[0]) {
            // for Mozilla/Opera9
            if (document.addEventListener)
                document.addEventListener("DOMContentLoaded", init, false);
            // for Internet Explorer
            /*@cc_on @*/
            /*@if (@_win32)
                document.write("<script id=__ie_onload defer src=//0><\/scr"+"ipt>");
                script = document.getElementById("__ie_onload");
                script.onreadystatechange = function() {
                    if (this.readyState == "complete")
                        init(); // call the onload handler
                };
            /*@end @*/
            // for Safari
            if (/WebKit/i.test(navigator.userAgent)) { // sniff
                load_timer = setInterval(function() {
                    if (/loaded|complete/.test(document.readyState))
                        init(); // call the onload handler
                }, 10);
            }
            // for other browsers set the window.onload, but also execute the old window.onload
            old_onload = window.onload;
            window.onload = function() {
                init();
                if (old_onload) old_onload();
            };
        }
        load_events.push(func);
    }
})();

//mini-biblio antique
LOC.getStyle = function(what){
	return(document.getElementById(what).style);
}
LOC.getObj = function(what){
	return(document.getElementById(what));
}
LOC.setPos = function(what, v1, v2){
	var obj = LOC.getStyle(what);
	p1 = v1.split("-")[1];
	if(v1.split("-")[0] == "x"){obj.left = p1;}
	else{obj.top = p1;}
	if(v2){
		p2 = v2.split("-")[1];
		if(v2.split("-")[0] == "x"){obj.left = p2;}
		else{obj.top = p2;}
	}
}
LOC.getPos = function(what){
	var obj = LOC.getObj(what);
	return([parseInt(obj.offsetLeft), parseInt(obj.offsetTop)]);
}
LOC.getAbsPos = function(what){
	var obj = (LOC.getObj(what)) ? LOC.getObj(what) : what;
	if(obj.offsetParent){return([obj.offsetLeft + LOC.getAbsPos(obj.offsetParent)[0], obj.offsetTop + LOC.getAbsPos(obj.offsetParent)[1]]);}
	else{return([obj.offsetLeft, obj.offsetTop]);}
}
LOC.setToAnchor = function(AnchorName,what){
	var MyAnchor = LOC.getObj(AnchorName);
	var x = LOC.getAbsPos(AnchorName)[0];
	var y = LOC.getAbsPos(AnchorName)[1];
	if(arguments.length==2){LOC.setPos(what, "x-" + x, "y-" + y);}
	else{
		if(arguments[2]=="x"){LOC.setPos(what, "x-" + x);}
		else{LOC.setPos(what, "y-" + y);}
	}
}
// MyClip = [top,right,bottom,left]
LOC.setClip = function(what,MyClip){LOC.getStyle(what).clip="rect(" + MyClip[0] + "px " + MyClip[1] + "px " + MyClip[2] + "px " + MyClip[3] + "px)";}
LOC.setDisplay = function(what,how){LOC.getStyle(what).display=how;}
LOC.setVisibility = function(what,how){LOC.getStyle(what).visibility=how;}
LOC.setWidth = function (what,w){LOC.getStyle(what).width=w;}
LOC.setHeight = function(what,h){LOC.getStyle(what).height=h;}
LOC.setZ = function(what,z){LOC.getStyle(what).zIndex=z;}
LOC.getDisplay = function(what){return(LOC.getStyle(what).display);}
LOC.getVisibility = function(what){return(LOC.getStyle(what).visibility);}
LOC.getWidth = function(what){return(LOC.getObj(what).offsetWidth);}
LOC.getHeight = function(what){return(LOC.getObj(what).offsetHeight);}
LOC.getZ = function(what){return(LOC.getStyle(what).zIndex);}
// ///////////////////////////// mainNav
//variables globales
LOC.IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
// exactly Internet Explorer 7
LOC.IE7 = false /*@cc_on || @_jscript_version == 5.7 @*/;
// at least Internet Explorer 7
LOC.gteIE7 = false /*@cc_on || @_jscript_version >= 5.7 @*/;
// any Internet Explorer (thanks to Dean)
LOC.isMSIE = /*@cc_on!@*/false;
var strChUserAgent = navigator.userAgent; 
var intSplitStart = strChUserAgent.indexOf("(",0); 
var intSplitEnd = strChUserAgent.indexOf(")",0); 
var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd); 
LOC.IE6 = (strChMid.indexOf("MSIE 6") != -1) ? true : false;
//array pour stocker les objets menu composant les menus de la mainNav
var navtopmenu_arr = new Array();
//indice rub
LOC.gRub = 4; //rubrique finance
//LOC.detec TAILLE ECRAN
LOC.detec = function(){
	//init des width et height de la fenêtre document.body.clientHeight
	initW = (window.innerWidth) ? window.innerWidth : (document.documentElement.clientWidth)?document.documentElement.clientWidth:document.body.clientWidth;
	initH = (window.innerHeight) ? window.innerHeight : (document.documentElement.clientHeight)?document.documentElement.clientHeight:document.body.clientHeight;
}
LOC.gMenuFocus; // pour gestion focus via touches flèches, indiquera l'id du ssmenu à highligther
LOC.gNbMenus; // pour gestion dernier menu, indiquera le nombre de menus
//init mainNav
LOC.initmainnav = function() {
	LOC.detec();
	document.documentElement.className = "js";
	var indicemenu = 0; //pour attribution id dynamique qui permet de gérer la navigation par touche tab et focus/blur
	var indicessmenu = 0; //pour attribution id dynamique qui permet de gérer la navigation par touche tab et focus/blur
	var menusmainNav = document.getElementById("topNav").getElementsByTagName("li");
	for (var i=0; i<menusmainNav.length; i++) {
		menusmainNav[i].onmouseover = function() {
			if(this.firstChild.className.indexOf("menu") >= 0 && this.firstChild.className.indexOf("ssmenu") < 0){
				this.className = "sfhover";
				this.firstChild.className = this.firstChild.className.replace(new RegExp("menu\\b"), "menuover");
				if(this.firstChild.className.indexOf("menuclicked") >= 0){
					this.firstChild.className = this.firstChild.className += " menuover";
				}
				//pour dernier menu
				if(this.indice == LOC.gNbMenus){
					if(this.getElementsByTagName("ul")[0]){
						var ssnav = this.getElementsByTagName("ul")[0];
						var ssmenus_arr = ssnav.getElementsByTagName("li");
						for(var u=0; u<ssmenus_arr.length; u++){
							var ssmenu = ssmenus_arr[u];
							ssmenu.style.textAlign = "right";// menu News
						}
						var ssnavwidth = ssnav.getElementsByTagName("li")[0].offsetWidth;
						var delta = this.offsetWidth - ssnavwidth;
						var pox = LOC.getAbsPos(this)[0]+ delta;
						ssnav.style.left = pox + "px";
					}
				}
				//pour rollover IE6
				if(LOC.IE6 && this.firstChild.className.indexOf("ssmenu") < 0){
					if(this.getElementsByTagName("ul")[0]){
						var ssnav = this.getElementsByTagName("ul")[0];
						var h = ssnav.offsetHeight;
						var w = ssnav.offsetWidth;
						var pox = LOC.getAbsPos(ssnav)[0];
						var poy = LOC.getAbsPos(ssnav)[1];
						LOC.setPos("masq", "x-" + pox, "y-" + poy);
						LOC.setWidth("masq", w);
						LOC.setHeight("masq", h);
						LOC.getStyle("masq").display = "block";
					}
				}
			}
			else if(this.firstChild.className == "ssmenu"){
				this.firstChild.className = "ssmenuover";
			}
		}
		menusmainNav[i].onmouseout = function() {
			this.className = this.className.replace(new RegExp("sfhover\\b"), "");
			if(this.firstChild.className.indexOf("menuclicked") >= 0){
				this.firstChild.className = this.firstChild.className.replace(" menuover", "");
			}
			if(this.firstChild.className == "menuover"){
				this.firstChild.className = "menu";
			}
			else if(this.firstChild.className == "ssmenuover"){
				this.firstChild.className = "ssmenu";
			}
			if(LOC.IE6){
				LOC.getStyle("masq").display = "none";
			}
			//pour dernier menu
			if(this.firstChild.className.indexOf("menu") >= 0 && this.firstChild.className.indexOf("ssmenu") < 0){
				if(this.indice == LOC.gNbMenus){
					if(this.getElementsByTagName("ul")[0]){
						var ssnav = this.getElementsByTagName("ul")[0];
						var pox = "-999em";
						ssnav.style.left = pox;
					}
				}
			}
		}
		//gestion focus et blur pour navigation par tabulation
		menusmainNav[i].getElementsByTagName("a")[0].onfocus = function(){
			//kill rollovers de tous les menus
			for(var n=0; n<navtopmenu_arr.length; n++){
				navtopmenu_arr[n].onmouseout();
			}
			//rollover de l'item (menu ou ssmenu)
			this.parentNode.onmouseover();
			//si ssmenu, rollover du menu parent (sinon, les ssmenus disparaissent car le menu parent perd le focus !)
			if(this.className.indexOf("ssmenu")>=0){
				this.parentNode.parentNode.parentNode.onmouseover();
			}
		}
		menusmainNav[i].getElementsByTagName("a")[0].onblur = function(){
			this.parentNode.onmouseout();
		}
		//fin gestion focus et blur pour navigation par tabulation
		//gestion accès sous-menus par flèches // < : 37, ^ : 38, > : 39, v : 40
		var zemenu = menusmainNav[i];
		if(zemenu.firstChild.className.indexOf("ssmenu") >= 0){
		//if(XML.get_firstChild(zemenu).className.indexOf("ssmenu") >= 0){
			zemenu.indiceparent = indicemenu - 1;
			zemenu.indice = indicessmenu;
			indicessmenu ++;
			zemenu.id = "menu" + zemenu.indiceparent + "ssmenu" + zemenu.indice;
			zemenu.onkeydown = function(e){
				var zekey = (window.event) ? window.event.keyCode : e.which; //window.event == IE
				if(zekey == 40){
					var nextmenu = "menu" + this.indiceparent + "ssmenu" + (this.indice + 1);
					if(document.getElementById(nextmenu)){
						LOC.gMenuFocus = document.getElementById(nextmenu).getElementsByTagName("a")[0];
						setTimeout("LOC.gMenuFocus.focus();", 100);
					}
				}
				if(zekey == 38){
					var prevmenu = "menu" + this.indiceparent + "ssmenu" + (this.indice - 1);
					if(document.getElementById(prevmenu)){
						LOC.gMenuFocus = document.getElementById(prevmenu).getElementsByTagName("a")[0];
						setTimeout("LOC.gMenuFocus.focus();", 100);
					}
				}
			}
		}
		else{
			zemenu.indice = indicemenu;
			indicemenu ++;
			indicessmenu = 0;
			zemenu.id = "menu" + zemenu.indice;
			zemenu.onkeydown = function(e){
				var zekey = (window.event) ? window.event.keyCode : e.which; //window.event == IE
				if(zekey == 40){
					var firstssmenua = this.getElementsByTagName("li")[0].getElementsByTagName("a")[0];
					firstssmenua.focus();
				}
			}
		}
		//gestion accès sous-menus par flèches
	}
	LOC.gNbMenus = indicemenu - 1; //nombre de menus dans la topNav
	//stockage éléments de mainnav dans un array global
	for (var i=0; i<menusmainNav.length; i++) {
		if(menusmainNav[i].firstChild.className == "menu"){
			navtopmenu_arr.push(menusmainNav[i]);
		}
	}
	//calage nav sur toute la largeur du 1024
	var maxW = 935;
	var oPadding = 4;
	var poxlastmenu = parseInt(LOC.getAbsPos(navtopmenu_arr[navtopmenu_arr.length - 1])[0] - LOC.getAbsPos("mainNav")[0]);
	var widthlastmenu = parseInt(navtopmenu_arr[navtopmenu_arr.length - 1].offsetWidth);
	var navW = poxlastmenu + widthlastmenu;
	var vide = Math.round(maxW - navW);
	var deltaX = Math.floor((vide / navtopmenu_arr.length) / 2);
	//modif padding de tous les tombs
	for(var i=0; i<navtopmenu_arr.length; i++){
		navtopmenu_arr[i].firstChild.style.paddingLeft = oPadding + deltaX + "px";
		navtopmenu_arr[i].firstChild.style.paddingRight = oPadding + deltaX + "px";
	}
	//modif paddings du dernier tomb pour combler les manques des Math.floor
	var poxlastmenu = LOC.getAbsPos(navtopmenu_arr[navtopmenu_arr.length - 1])[0] - LOC.getAbsPos("mainNav")[0];
	var widthlastmenu = navtopmenu_arr[navtopmenu_arr.length - 1].offsetWidth;
	var navW = poxlastmenu + widthlastmenu;
	var reste = Math.floor(maxW - navW);
	var g = Math.floor(reste/2);
	var d = Math.ceil(reste/2);
	var valg = oPadding + deltaX + g;
	var vald = oPadding + deltaX + d;
	navtopmenu_arr[navtopmenu_arr.length - 1].firstChild.style.paddingLeft = valg + "px";
	navtopmenu_arr[navtopmenu_arr.length - 1].firstChild.style.paddingRight = vald + "px";
	navtopmenu_arr[navtopmenu_arr.length - 1].firstChild.style.background = "transparent";
	//fin calage nav sur toute la largeur du 1024
	//highlight menu de la rubrique en cours
	for(var i=0; i<navtopmenu_arr.length; i++){
		if(i.toString() == LOC.gRub.toString()){//toString pour éviter le problème false == 0 !
			navtopmenu_arr[i].firstChild.className = "menuclicked";
		}
	}
	//rollover par focus touche tab
	var eltscoul = ["mainNavTools", "bottomNav"];
	for(var z=0; z<eltscoul.length; z++){
		if(document.getElementById(eltscoul[z])){
			elt = document.getElementById(eltscoul[z]);
			var eltsa = elt.getElementsByTagName("a");
			for(var zz=0; zz<eltsa.length; zz++){
				var elta = eltsa[zz];
				elta.initColor = elta.style.color;
				elta.onfocus = function(){
					this.style.color = "#FFFFFF";
				}
				elta.onblur = function(){
					this.style.color = this.initColor;
				}
			}
		}
	}
}
//onload events
LOC.addDOMLoadEvent(function(){
	LOC.initmainnav();
});