var NAVIGATION_INIT = false;

// BrowserCheck Object
function BrowserCheck() {
	var ua = navigator.userAgent.toLowerCase(); 
	
	// browser engine name
	this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
	this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);
	
	// browser name
	this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
	this.isSafari      = (ua.indexOf('safari') != - 1);
	this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
	this.isOpera       = (ua.indexOf('opera') != -1); 
	this.isIcab        = (ua.indexOf('icab') != -1); 
	this.isAol         = (ua.indexOf('aol') != -1); 
	this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
	this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
	this.isFirebird    = (ua.indexOf('firebird/') != -1);
	this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
	
	// spoofing and compatible browsers
	this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
	this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
	
	// rendering engine versions
	this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
	this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
	this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
	
	// browser version
	this.versionMinor = parseFloat(navigator.appVersion); 
	
	// correct version number
	if (this.isGecko && !this.isMozilla) {
	   this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
	}
	else if (this.isMozilla) {
	   this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
	}
	else if (this.isIE && this.versionMinor >= 4) {
	   this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
	}
	else if (this.isKonqueror) {
	   this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
	}
	else if (this.isSafari) {
	   this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
	}
	else if (this.isOmniweb) {
	   this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
	}
	else if (this.isOpera) {
	   this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
	}
	else if (this.isIcab) {
	   this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
	}
	
	this.versionMajor = parseInt(this.versionMinor); 
	
	// dom support
	this.isDOM1 = (document.getElementById);
	this.isDOM2Event = (document.addEventListener && document.removeEventListener);
	
	// css compatibility mode
	this.mode = document.compatMode ? document.compatMode : 'BackCompat';
	
	// platform
	this.isWin    = (ua.indexOf('win') != -1);
	this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
	this.isMac    = (ua.indexOf('mac') != -1);
	this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
	this.isLinux  = (ua.indexOf('linux') != -1);
	
	// specific browser shortcuts
	this.isNS4x = (this.isNS && this.versionMajor == 4);
	this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
	this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
	this.isNS4up = (this.isNS && this.versionMinor >= 4);
	this.isNS6x = (this.isNS && this.versionMajor == 6);
	this.isNS6up = (this.isNS && this.versionMajor >= 6);
	this.isNS7x = (this.isNS && this.versionMajor == 7);
	this.isNS7up = (this.isNS && this.versionMajor >= 7);
	
	this.isIE4x = (this.isIE && this.versionMajor == 4);
	this.isIE4up = (this.isIE && this.versionMajor >= 4);
	this.isIE5x = (this.isIE && this.versionMajor == 5);
	this.isIE55 = (this.isIE && this.versionMinor == 5.5);
	this.isIE5up = (this.isIE && this.versionMajor >= 5);
	this.isIE6x = (this.isIE && this.versionMajor == 6);
	this.isIE6up = (this.isIE && this.versionMajor >= 6);
	
	this.isIE4xMac = (this.isIE4x && this.isMac);
}

// TOP NAVIGATION

function generateImagePathLocalized(path) {
	return (ImagePrefix + "/" + Language + path);
}

function generateImagePath(path) {
	return (ImagePrefix + path);
}

function topnavOver(idx) {
	if(NAVIGATION_INIT)
		document.images["topnav_" + idx].src = topnav_on[idx].src;
}

function topnavOut(idx) {
	if(NAVIGATION_INIT)
		document.images["topnav_" + idx].src = topnav_off[idx].src;
}

// MAIN NAVIGATION

function syncNav() {
	if(NAVIGATION_INIT)
	{
		if (Rub > 0) changeBackground(Rub, true, '#000000');
		//alert(typeof(NbEspaceRubz));
		if (typeof(NbEspaceRub) == "number") {
			if (EspaceRub > 0) changeBackgroundEspace(EspaceRub, true, '#DC9265');
			}
	}
}

function changeBackground(idx, over, color) {
	if(NAVIGATION_INIT)
	{
		idx = parseInt(idx);

		var obj = (is.isIE) ? eval("document.all.oNav" + idx):document.getElementById('oNav' + idx);
		if ((is.isSafari) && (over==false)) { 
		obj.style.background = 'transparent';
		} else { 
		obj.style.background = color;
		}
		if (over) {
			if (idx == 1) {
				document.images['mainnav_1'].src = mainnav_sep_1eft_o.src;
				document.images['mainnav_' + (idx + 1)].src = mainnav_sep_o.src;
			} else if (idx > 1 && idx < NbRub) {
				document.images['mainnav_' + idx].src = mainnav_sep_o.src;
				document.images['mainnav_' + (idx + 1)].src = mainnav_sep_o.src;
			} else if (idx == NbRub) {
				document.images['mainnav_' + idx].src = mainnav_sep_o.src;
				document.images['mainnav_' + (idx + 1)].src = mainnav_sep_right_o.src;
			}
		} else {
			if (idx == 1) {
				document.images['mainnav_1'].src = mainnav_sep_1eft_f.src;
				if (Rub != idx + 1) document.images['mainnav_' + (idx + 1)].src = mainnav_sep_f.src;
			} else if (idx > 1 && idx < NbRub) {
				if (Rub != idx - 1) document.images['mainnav_' + idx].src = mainnav_sep_f.src;
				if (Rub != idx + 1) document.images['mainnav_' + (idx + 1)].src = mainnav_sep_f.src;
			} else if (idx == NbRub) {
				if (Rub != idx - 1) document.images['mainnav_' + idx].src = mainnav_sep_f.src;
				document.images['mainnav_' + (idx + 1)].src = mainnav_sep_right_f.src;
			}
		}
	}
}

function mainnavOver(idx) {
	if(NAVIGATION_INIT)
	{
		idx = parseInt(idx);
		changeBackground(idx, true, '#000000');

		var oMenu = (is.isIE) ? eval("document.all.oMenu" + idx):document.getElementById('oMenu' + idx);
		var oOrigin = (is.isIE) ? eval("document.all.oOrigin" + idx):document.getElementById('oOrigin' + idx);
		if (typeof (oMenu) != "undefined" && oMenu != null) {
			if (is.isIE && !is.isMac) {
				if (idx == NbRub) {
					ecart = eval("document.all.oOrigin" + (idx + 1) + ".offsetLeft") - oOrigin.offsetLeft + 28;
					if (ecart > 182) {
						xDelta = 0;
					} else {
						xDelta = 182 - ecart;
					}
				} else {
					xDelta = 0;
				}
				oMenu.style.left = oOrigin.offsetLeft - xDelta;
				oMenu.style.visibility = 'visible';
			}
			if (is.isIE && is.isMac) { 
			
				
				function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
				function getAbsPos(elt,which)
				{
					iPos = 0;
					while (elt != null)
					{
						iPos += elt["offset" + which];
						elt = elt.offsetParent;
					}
					return iPos;
				}
				monImg = getAbsX(document.getElementById('oOrigin' + (idx)));
				
				document.getElementById('oMenu'+idx).style.left = monImg + 'px';
				oMenu.style.visibility = 'visible';
			} else { 
				if (idx == NbRub) {
					ecart = document.getElementById('oOrigin' + (idx + 1)).offsetLeft - oOrigin.offsetLeft + 28;
					if (ecart > 182) {
						xDelta = 0;
					} else {
						xDelta = 182 - ecart;
					}
				} else {
					xDelta = 0;
				}
				document.getElementById('oMenu'+idx).style.left = (oOrigin.offsetLeft - xDelta) + 'px';
				oMenu.style.visibility = 'visible';
			}
		}
	}
}

function fadeIn(i,j,fadeObject) {
	if(NAVIGATION_INIT)
	{
		document.all.oMenu1.filters.alpha.opacity = i;
		i += 9;
		if (i < j) setTimeout("fadeIn(" + i + "," + j + ",'" + fadeObject + "')",0);
	}
}

function mainnavOut(idx) {
	if(NAVIGATION_INIT)
	{
		if (idx != Rub) changeBackground(idx, false, '');
		var oMenu = (is.isIE) ? eval("document.all.oMenu" + idx):document.getElementById('oMenu' + idx);
		if (typeof (oMenu) != "undefined" && oMenu != null) {
			if (is.isIE) {
				oMenu.style.visibility = 'hidden';
			} else {
				oMenu.style.visibility = 'hidden';
			}
		}
	}
}

function smainnavOver(obj) {
	if(NAVIGATION_INIT)
		obj.style.background = "#FFFFFF";
}

function smainnavOut(obj) {
	if(NAVIGATION_INIT)
		obj.style.background = "#E3D935";
}

function gotoPage(url) {
	if (url != "") {
		document.location = url;
	}
}


// SOUS RUBRIQUES NAVIGATION

function leftsnavOver(idx) {
	if(NAVIGATION_INIT)
	{
		if (lastSNav != "" && lastSNav != idx) {
			hideleftsnavOut(lastSNav);
		}
		lastSNav = idx;
		clearTimeout(snavTimer);
		var oMenu = (is.isIE) ? eval("document.all.oLeftSNav" + idx):document.getElementById('oLeftSNav' + idx);
		var oOrigin = (is.isIE) ? eval("document.all.oOriginLeftSNav" + idx):document.getElementById('oOriginLeftSNav' + idx);
		if (typeof (oMenu) != "undefined" && oMenu != null) {
			if (is.isIE) {
				var sctop = (is.isIE6up)
					? document.documentElement.scrollTop
					: document.body.scrollTop;

				oMenu.style.top = oOrigin.getBoundingClientRect().top + sctop + 6;
				//oMenu.style.left = oOrigin.getBoundingClientRect().left - 7;
				oMenu.style.left = oOrigin.getBoundingClientRect().left + oOrigin.offsetWidth - oMenu.offsetWidth + 22;
				oMenu.style.visibility = 'visible';
			} else {
				document.getElementById('oLeftSNav' + idx).style.top = oOrigin.offsetTop + 8 + 'px';
				//document.getElementById('oLeftSNav' + idx).style.left = oOrigin.offsetLeft - 5 + 'px';
				document.getElementById('oLeftSNav' + idx).style.left = (oOrigin.offsetLeft + oOrigin.offsetWidth - oMenu.offsetWidth + 24) + 'px';
				oMenu.style.visibility = 'visible';
			}
		}
	}
}

function leftsnavOut(idx) {
	if(NAVIGATION_INIT)
		snavTimer = setTimeout("hideleftsnavOut(" + idx + ");", 0);
}

function hideleftsnavOut(idx) {
	if(NAVIGATION_INIT)
	{
		var oMenu = (is.isIE) ? eval("document.all.oLeftSNav" + idx):document.getElementById('oLeftSNav' + idx);
		if (typeof (oMenu) != "undefined" && oMenu != null) {
			if (isIE) {
				oMenu.style.visibility = 'hidden';
			} else {
				oMenu.style.visibility = 'hidden';
			}
		}
	}
}


// ESPACE PERSO NAVIGATION
function espacenavOver(idx) {
	if(NAVIGATION_INIT)
		changeBackgroundEspace(idx, true, '#DC9265');
}

function espacenavOut(idx) {
	if(NAVIGATION_INIT)
		if (idx != EspaceRub) changeBackgroundEspace(idx, false, '');
}

function changeBackgroundEspace(idx, over, color) {
	var obj = (is.isIE) ? eval("document.all.oEspaceNav" + idx):document.getElementById('oEspaceNav' + idx);
	obj.style.background = color;
    var obj2 = (is.isIE) ? eval("document.all.oEspaceLink" + idx):document.getElementById('oEspaceLink' + idx);
	var prevIdx = Number(idx) - 1;
	var nextIdx = Number(idx) + 1;
    if (over) {
        obj2.className = "espacenavover";
		if (idx == 1) {
			document.images['espacenav_1'].src = espacenav_sep_1eft_o.src;
			document.images['espacenav_' + nextIdx].src = espacenav_sep_o.src;
		} else if (idx > 1 && idx < NbEspaceRub) {
			document.images['espacenav_' + idx].src = espacenav_sep_o.src;
			document.images['espacenav_' + nextIdx].src = espacenav_sep_o.src;
		} else if (idx == NbEspaceRub) {
			document.images['espacenav_' + idx].src = espacenav_sep_o.src;
			document.images['espacenav_' + nextIdx].src = espacenav_sep_right_o.src;
		}
	} else {
        obj2.className = "espacenav";
		if (idx == 1) {
			document.images['espacenav_1'].src = espacenav_sep_1eft_f.src;
			if (EspaceRub != nextIdx) document.images['espacenav_' + nextIdx].src = espacenav_sep_f.src;
		} else if (idx > 1 && idx < NbEspaceRub) {
			if (EspaceRub != prevIdx) document.images['espacenav_' + idx].src = espacenav_sep_f.src;
			if (EspaceRub != nextIdx) document.images['espacenav_' + nextIdx].src = espacenav_sep_f.src;
		} else if (idx == NbEspaceRub) {
			if (EspaceRub != prevIdx) document.images['espacenav_' + idx].src = espacenav_sep_f.src;
			document.images['espacenav_' + nextIdx].src = espacenav_sep_right_f.src;
		}
	}
}



// BOTTOM NAVIGATION
function bottomnavOver(idx) {
	if(NAVIGATION_INIT)
		document.images["bottomnav_" + idx].src = bottomnav_on[idx].src;
}

function bottomnavOut(idx) {
	if(NAVIGATION_INIT)
		document.images["bottomnav_" + idx].src = bottomnav_off[idx].src;
}

// TOOLS NAVIGATION
function toolsnavOver(idx) {
	if(NAVIGATION_INIT)
		document.images["toolsnav_" + idx].src = toolsnav_on[idx].src;
}

function toolsnavOut(idx) {
	if(NAVIGATION_INIT)
		document.images["toolsnav_" + idx].src = toolsnav_off[idx].src;
}

// INPUT ACTIONS
function enterInput(obj,text) {
	if (obj.value == text) {
		obj.value = "";
	}
}

function leaveInput(obj,text) {
	if (obj.value == "") {
		obj.value = text;
	}
}

// POPUP
function deplace(window,width,height) {
	if(NAVIGATION_INIT)
	{
		var scr_x = screen.width;
		var scr_y = screen.height;
		if (is.v >= 4) {
			if (is.ns) {
				window.moveTo((scr_x/2)-(width/2), (scr_y/2)-(height/2));
			} else {
				window.moveTo(parent.window.screenLeft+300, parent.window.screenTop+50);
			}
		}
	}
}
	
function openPopup(url,width,height) {
	if(NAVIGATION_INIT)
	{
		if (url != "") {
			var features;
			var windowName = "ZOOMWINDOW";
			features = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" + scrollPopup + ",resizable=0,width=" + width + ",height=" + height + "'";
			movePopup = true;
			scrollPopup = 1;
			if (openPopup.arguments.length >= 4) {
				if (openPopup.arguments[3]) {
					movePopup = true;
				} else {
					movePopup = false;
				}
			}
			if (openPopup.arguments.length >= 5) {
				if (openPopup.arguments[4] == 0 || openPopup.arguments[4] == 1) {
					scrollPopup = openPopup.arguments[4];
				}
			}
			if (openPopup.arguments.length >= 6) {
				zoomwindow = openPopup.arguments[5];
				windowName = zoomwindow;
			} else {
				if (zoomwindow != null) {
					if (!zoomwindow.closed)
						zoomwindow.close();
				}
			}
			zoomwindow = window.open(url,windowName,features);
			if (is.versionMajor == 3 || is.versionMajor == 4) {
				zoomwindow.focus();
			}
			if (movePopup) deplace(zoomwindow,width,height);
		}
	}
}
