// JavaScript Document
var JQuery_estPresent = (typeof jQuery != "undefined")?true:false;

if(JQuery_estPresent){
	jQ = jQuery.noConflict(true);
}
	
window.onload = function(){
	reziseContent(document.getElementById('imageFond'));

}
window.onresize = function(){
	//reziseContent(document.getElementById('imageFond'));
}


function fermerReponse(id){
	document.getElementById(id).innerHTML="";
	document.getElementById(id).style.visibility="hidden";
	document.getElementById(id).style.width = "0px";
	document.getElementById(id).style.height = "0px";
	document.getElementById(id).style.top = "0px";
	document.getElementById(id).style.left = "0px";
	}

function afficherMessage(message,id){
	document.getElementById(id).style.visibility="visible";
	document.getElementById(id).innerHTML = message;
}
function effacerMessage(id){
	document.getElementById(id).style.visibility="hidden";
	document.getElementById(id).innerHTML = "";
}


function afficherReponse(message,id){
	unEcran = new Ecran();
	var calqueRef = "divTexte";
	var largeurEcran = unEcran.largeur;
	var centre = largeurEcran /2 ;
	document.getElementById(id).style.visibility="visible";
	document.getElementById(id).innerHTML="<center><table style='background-color:#000;color:#FFF;'  width='100%' height='100%' ><tr><td align='center' style='word-wrap: break-word'>"+ message+"</td></tr><tr><td align='center'><a href='javascript:fermerReponse(\""+id+"\");' style='text-decoration:none;color:#fff;'>FERMER</a></td></tr></table></center>";

	document.getElementById(id).style.width = largeurEcran+"px";
	//document.getElementById(id).style.height = document.getElementById(calqueRef).offsetHeight/2 +"px";
	var centreId = document.getElementById(id).offsetWidth /2 ;
	var decLeft = centre - centreId;
	document.getElementById(id).style.top = unEcran.hauteur/2 +"px";
	document.getElementById(id).style.left = decLeft+"px";

	document.getElementById(id).style.position = "absolute";
	document.getElementById(id).style.paddingTop = "10%";
	document.getElementById(id).style.zindex = "1";
}	

function cacheLoggin(){
	unEcran = new Ecran();
	if(document.getElementById("aConteneur")){
		document.getElementById("aConteneur").style.width = unEcran.largeur-140+'px';
		document.getElementById("aConteneur").style.height = unEcran.hauteur+'px';
	}
}

function reziseContent(div){
	if(div){
		var decalIE = 0;
		if(jQ.browser.msie)
			decalIE = 22;
		var limiteLargeur = 1024;
		var h = document.getElementById('imageFond').offsetHeight;
		var l = document.getElementById('imageFond').offsetWidth;
		homothetie = h/l;
		var marge = 80;
		var unEcran = new Ecran();
		
		if(unEcran.largeur < limiteLargeur)
			unEcran.largeur = limiteLargeur;
		
		div.style.width = unEcran.largeur-marge+"px";
		var maHauteur =  homothetie * div.offsetWidth;
		div.style.height = (maHauteur)+"px";
		
	
		var rapport = l/( div.offsetWidth);
		resizeElement("logo","div_logo",rapport);
		
		resizeElement("titre","div_titre",rapport);
		
		resizeElement("menu1","div_menu1",rapport);
		resizeElement("menu2","div_menu2",rapport);
		resizeElement("menu3","div_menu3",rapport);
		resizeElement("menu4","div_menu4",rapport);
		
		resizeElement("lien1","div_lien",rapport);
		resizeElement("lien2","div_lien",rapport);
	
		resizeElement("diapositives_01","div_diapositives",rapport);		
		resizeElement("diapositives_02","div_diapositives",rapport);
		resizeElement("diapositives_03","div_diapositives",rapport);
		resizeElement("diapositives_04","div_diapositives",rapport);
		
		resizeElement("liens_00","div_liens_00",rapport);
		resizeElement("liens_01","div_liens_01",rapport);		
		resizeElement("liens_02","div_liens_02",rapport);
		resizeElement("liens_03","div_liens_03",rapport);
		resizeElement("liens_04","div_liens_04",rapport);
		resizeElement("liens_05","div_liens_05",rapport);
		resizeElement("liens_06","div_liens_06",rapport);
		resizeElement("liens_07","div_liens_07",rapport);

		
		positionnerLogo("div_logo",div);
		positionnerLayer("div_titre",div,rapport,756+decalIE,20+decalIE);
		
		positionnerLayer("div_menu1",div,rapport,703+decalIE,279+decalIE);
		positionnerLayer("div_menu2",div,rapport,483+decalIE,457+decalIE);
		positionnerLayer("div_menu3",div,rapport,260+decalIE,626+decalIE);
		positionnerLayer("div_menu4",div,rapport,52+decalIE,807+decalIE);
		
		positionnerLayer("div_lien",div,rapport,365+decalIE,1193+decalIE);
		
		positionnerLayer("div_diapositives",div,rapport,126+decalIE,936+decalIE);
		
		var initxliens = 454;
		var inityliens = 834;
		var xliens =50;
		var yliens =70;
		positionnerLayer("div_liens_00",div,rapport,888+decalIE,730+decalIE);
		positionnerLayer("div_liens_01",div,rapport,initxliens+decalIE,inityliens+decalIE);
		positionnerLayer("div_liens_02",div,rapport,initxliens-xliens+decalIE,inityliens+yliens+decalIE);
		positionnerLayer("div_liens_03",div,rapport,initxliens-(2*xliens)+decalIE,inityliens+(2*yliens)+decalIE);
		positionnerLayer("div_liens_04",div,rapport,initxliens-(3*xliens)+decalIE,inityliens+(3*yliens)+decalIE);
		positionnerLayer("div_liens_05",div,rapport,initxliens-(4*xliens)+decalIE,inityliens+(4*yliens)+decalIE);
		positionnerLayer("div_liens_06",div,rapport,initxliens-(5*xliens)+decalIE,inityliens+(5*yliens)+decalIE);
		positionnerLayer("div_liens_07",div,rapport,initxliens-(6*xliens)+decalIE,inityliens+(6*yliens)+decalIE);

		positionnerLayer("div_formContact",div,rapport,770+decalIE,350+decalIE);

		
		//alert(div.offsetHeight);
		
		binderClick();
	}
}
function positionnerLogo(div,conteneur){
	
	var id = document.getElementById(div);
	if(id){
		id.style.left = conteneur.offsetLeft +"px";
		id.style.top = conteneur.offsetTop +"px";
	}
	
}
function positionnerLayer(div,conteneur,rapport,x,y){
	var id = document.getElementById(div);
	if(id){
		var gauche = x/rapport + conteneur.offsetLeft;
		var haut = y/rapport + conteneur.offsetTop;
		id.style.left = gauche +"px";
		id.style.top = haut +"px";
	}
}


function resizeElement(div,div2,rapport){
	
	var id = document.getElementById(div);
	if(id){
		var conteneur = document.getElementById(div2);
		
		var maLargeur = id.offsetWidth/rapport;
	
		id.style.width = (maLargeur)+"px";
		var maHauteur =  id.offsetHeight/rapport ;
		id.style.height = (maHauteur)+"px";
		
		var largeurT = id.offsetWidth;
		var hauteurT = id.offsetHeight;
		
		
		conteneur.style.width =  largeurT+"px";
		conteneur.style.height =  hauteurT+"px";
		
	}
		
		
}

function binderClick(){
	//alert(jQ('div_logo').length);
	
	jQ('#div_menu1').click(function (){document.location.href = "page1.html";});
	jQ('#div_menu2').click(function (){document.location.href = "page2.html";});
	jQ('#div_menu3').click(function (){document.location.href = "page3.html";});
	jQ('#div_menu4').click(function (){document.location.href = "page4.html";});
	jQ('#div_logo').click(function (){document.location.href = "index.html";})
	jQ('#lien1').click(function (){document.location.href = "page5.html";})
	jQ('#lien2').click(function (){document.location.href = "page6.html";})
	
	jQ('#diapositives_01').click(function (){window.open(jQ(this).attr('href'),'blank');})
	jQ('#diapositives_02').click(function (){window.open(jQ(this).attr('href'),'blank');})
	jQ('#diapositives_03').click(function (){window.open(jQ(this).attr('href'),'blank');})
	jQ('#diapositives_04').click(function (){window.open(jQ(this).attr('href'),'blank');})
	
	
	jQ('#liens_01').click(function (){window.open(jQ(this).attr('href'),'blank');})
	jQ('#liens_02').click(function (){window.open(jQ(this).attr('href'),'blank');})	
	jQ('#liens_03').click(function (){window.open(jQ(this).attr('href'),'blank');})
	jQ('#liens_04').click(function (){window.open(jQ(this).attr('href'),'blank');})
	jQ('#liens_05').click(function (){window.open(jQ(this).attr('href'),'blank');})	
	jQ('#liens_06').click(function (){window.open(jQ(this).attr('href'),'blank');})	
	jQ('#liens_07').click(function (){window.open(jQ(this).attr('href'),'blank');})	


}

function Ecran(){
	var taille = obtenirTaillePage();
var larg = taille[0];
var haut = taille[1];

this.largeur = larg;
this.hauteur = haut;
}

function obtenirTaillePage(){
	var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;

		if (self.innerHeight) {	// all except Explorer
				
			if(document.documentElement.clientWidth){
				
				windowWidth = document.documentElement.clientWidth; 
			} else {
				
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
					
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
					
			windowWidth = 	document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			//special !!!
			pageWidth = windowWidth;		
		} else {
			
			pageWidth = windowWidth;
		}
		if( pageHeight>screen.availHeight){
			pageHeight = screen.availHeight;
			pageHeight -= 150;
		}else{
			pageHeight -= 40;
		}
		
		//screen.availWidth; //

		return [pageWidth,pageHeight];
}

function attente(nbImg){
	var fondLoader = false;
	var tabImage = new Array(nbImg);
	var nbEnCours= 0;
	jQ("div").fadeOut(0);
	jQ("#div_attente").fadeIn(0);
	jQ("#imageFond").load( function() {fondLoader = true;jQ("#div_imageFond").fadeIn(0);});
  	jQ("img").load( function() { IDcalque = this.id;
		
		var chaine = IDcalque.substr(0,4);
		if(chaine == "lien"){ IDcalque = "lien";}
		tabImage[nbEnCours] = "#div_"+IDcalque; nbEnCours++; if(nbEnCours >= nbImg && fondLoader){for(i=0;i < nbImg;i++){jQ(tabImage[i]).fadeIn(0);}if(fondLoader){jQ("#div_attente").hide("fast");}}
		});
  // attendre que tout soit charge avant d afficher le site
  //stocker les div dans un tableau et reparser pour les afficher
  // une fois tout charge redimensionner le tout ca se fait automatiquement

   
}

