var isMozilla = (navigator.userAgent.toLowerCase().indexOf('gecko')!=-1) ? true : false;
var isIE6 = (navigator.userAgent.toLowerCase().indexOf('msie 6.0')!=-1) ? true : false;
var isIE = (navigator.userAgent.toLowerCase().indexOf('msie')!=-1) ? true : false;

/************************************************************/
/**************** FONCTIONS GENERIQUES  *********************/
/************************************************************/
   
function findPos(obj) {
	var curleft = obj.offsetLeft || 0;
	var curtop = obj.offsetTop || 0;
	while (obj = obj.offsetParent) {
	        curleft += obj.offsetLeft
	        curtop += obj.offsetTop
	}
	return {x:curleft,y:curtop};
} 

/***********************************************************************/
/****** RESIZING DE LA MARGE A GAUCHE POUR LE COIN ET LA HAUTEUR ********/
/***********************************************************************/
function resizeMg() {
	
	//Hauteur pour IE6
	if (isIE6) {
		document.getElementById("marge").style.height= document.getElementById("conteneur").offsetHeight;		
		document.getElementById("marge2").style.height= document.getElementById("conteneur").offsetHeight;		
	}		

	
	//pour coin gauche bas seulement si la derniere rubrique est expand	
	var marge = document.getElementById("marge");
	var marge2 = document.getElementById("marge2");	
	var lastRubObj = a_rubrique[a_rubrique.length-1];		
	if (!lastRubObj.ouvert) {
		marge.className="collapse";	
		marge2.className="collapse2";			
	}else{
		marge.className="expand";	
		marge2.className="expand2";
	}
	
	var ww = getWindowWidth();
	document.getElementById("conteneur").style.width = ww + "px";
}
/******************************************/
/****** RESIZING DE L'IMAGE DE FOND ********/
/******************************************/
/*
PRINCIPES :
cas 1 : largeur de la fenetre supérieur à 1024 >> l'image s'étire proportionnellement
cas 2 : largeur de la fenetre inferieur à 1024 >> la largeur est à 1024
cas 3 : si le contenu depasse la hauteur du fond >> la hauteur s'etire proportionnellement
*/
	
function getWindowWidth() {
	if (window.innerWidth) return window.innerWidth;
	else if (document.body && document.body.offsetWidth) return document.body.offsetWidth;
	else return 0;
}

function resizeBg() {

	var confWidth = 1024;
	var confHeight = 768;	
	var bgimg = document.getElementById("bgimg");	
	var conteneur = document.getElementById("conteneur");	
	
	if (getWindowWidth() > confWidth) 	{
		//cas 1 : 
		bgimg.width = parseInt(getWindowWidth());		
	} else {
		//cas 2:
		bgimg.width = confWidth;
	}
		
	var pourcRes = (parseInt(getWindowWidth())*100)/confWidth;
	var imgHeight = parseInt((pourcRes*confHeight)/100);
	var contHeight = parseInt(conteneur.offsetHeight);
	if ( imgHeight < contHeight) {
		//cas 3 : 
		bgimg.height = contHeight;
		pourcRes = (contHeight*100)/confHeight;
		var imgWidth = parseInt((pourcRes*confWidth)/100);
		bgimg.width = imgWidth;
	}
	
}
function verifXMLNodes(tag) {
	
	var bOK = false;
	if (tag.length > 0) {
		if (tag[0].hasChildNodes()) {
			bOK = true;
		}
	}
	return bOK
}

function replaceDiaporama(){
	
	var int_scroll = 0;
	if (isIE) {
		int_scroll = document.documentElement.scrollTop;
	}else{
		int_scroll = window.pageYOffset;
	}
	var div = document.getElementById("diapo");
	var div_fermer = document.getElementById("diapo_fermer");
	div.style.top = int_scroll + 'px';
	div_fermer.style.top = int_scroll + 'px';
}
 
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
function collapseAll() {
	for (var i=0;i<a_rubrique.length;i++) {
		if (a_rubrique[i].type=="projets") {
			for (var j=0;j<a_rubrique[i].content.length;j++) {
				a_rubrique[i].content[j].close();
			}
		}
		a_rubrique[i].setOuverture(false);
		//a_rubrique[i].setBottom(false);
	}
	resizeMg();
}
/******************************************/
/****** BOUTONS DE GAUCHE ********/
/******************************************/
function hideBt() {
	var div_bt = $('bt'); 
	div_bt.hide();

}
function showBt() {
	var div_bt = $('bt'); 
	div_bt.show();

	
}
function setBtStatus() {
	var b=false;
	for (var i=0;i<a_rubrique.length;i++) {
		if (a_rubrique[i].ouvert == true) {
			b = true;
		}
	}
	if (b==true) {
		showBt();
	}else{
		hideBt();
	}
}

window.onscroll = function() {
        positionBt();
}
window.onresize  = function() {
        resizeBg();
}
function positionBt() {
	if (isIE6) {
		var int_scroll = document.documentElement.scrollTop;
		var div_bt = $('bt'); 
		div_bt.style.top = int_scroll + 'px';
		//var int_scroll = document.documentElement.scrollTop;
		//var div_bg = $('fond'); 
		//div_bg.style.top = int_scroll + 'px';
	}
}
function setBgStatus() {
	if (isIE6) resizeBg();
}

function nb_aleatoire(nb)
{
	
} 

function switchBg() {
	var nombre= Math.floor(Math.random() * a_background.length)+1;	
	var index = nombre-1;
	if (Number(index)==Number(currBg)) {
		switchBg();
	}else{
		var imgBg = document.getElementById("bgimg");
		imgBg.src = "content/00_background/"+a_background[index];
		currBg = index;
	}
	
}
function test(obj, indic) {
	//var wi = obj.width;
	//wi = wi - 8;
	//var hei = obj.height;
	//hei = hei - 8;
	//document.getElementById(indic).style.width = wi+"px";
	//document.getElementById(indic).style.height = hei+"px";
	//return false;
}
function displayCadre(indic){
	//document.getElementById(indic).style.display = "block";
}
function hideCadre(indic){
	//document.getElementById(indic).style.display = "none";
}

NavName = navigator.appName.substring(0,3);
NavVersion = navigator.appVersion.substring(0,1);
if (NavName != "Mic" || NavVersion>=4)
{
entree = new Date;
entree = entree.getTime();
}
function ZsortIe()
{
if (NavName != "Mic" || NavVersion>=4)
{
fin = new Date;
fin = fin.getTime();
secondes = (fin-entree)/1000;
window.status='Page chargée en ' + secondes + ' seconde(s).';
}
}
