// JavaScript Document

function cacherMontrer(NomDiv)
{
	if($(NomDiv).visible())
	{
		$(NomDiv).hide();
	}
	else
	{
		$(NomDiv).show();
	}
} 

// annule le grisage du site et cache la pop up des photos ou des actualités
function fermerPopUp()
{
	$('cadreActu').hide();
	$('zoomPhoto').hide();
	$('overlay').hide();
}
		
//centre un div passé en paramètre
function centrerDiv(sId,largeur,hauteur)
{
	var height=document.getElementById(sId).offsetHeight;//hauteur de l'élément à positionner
	if (hauteur)
		height = hauteur;
	var width=document.getElementById(sId).offsetWidth;//largeur de l'élément à positionner
	if (largeur)
		width = largeur;
	var pHeight=hauteur_fenetre();//Hauteur de l'élément parent
	var pWidth=largeur_fenetre();//Largeur de l'élément parent
	var posY=(pHeight/2)-(height/2)+(getScrollY()-20); //getScrollY est utile pour ajouter la hauteur de l'ascenceur
	if (posY <0 ) posY = 0;
	var posX=(pWidth/2)-(width/2);
	if (posX <0 ) posX = 0;
	document.getElementById(sId).style.top=posY+"px";
	document.getElementById(sId).style.left=posX+"px";
}

//centre un div par rapport à un autre div
function centrerDivByDiv(sId, sIdCentrage, width,height)
{
	var height=height;//hauteur de l'élément à positionner
	var width=width;//largeur de l'élément à positionner
	var pHeight=document.getElementById(sIdCentrage).offsetHeight;//hauteur de l'élément à positionner
	var pWidth=document.getElementById(sIdCentrage).offsetWidth;//largeur de l'élément à positionner
	var top = document.getElementById(sIdCentrage).style.top;
	top = top.replace('px','');
	top = parseInt(top);
	var left = document.getElementById(sIdCentrage).style.left;
	left = left.replace('px','');
	left = parseInt(left);
	var posY=(pHeight/2)-(height/2) + top ;
	var posX=(pWidth/2)-(width/2) + left;
	document.getElementById(sId).style.top=posY+"px";
	document.getElementById(sId).style.left=posX+"px";
}

// retourne la largeur de la fenêtre du navigateur
function largeur_fenetre()
{
 if( typeof( window.innerWidth ) == 'number' ) {
	myWidth = window.innerWidth;
 } 
 else if( document.documentElement && document.documentElement.clientWidth  ) {
	myWidth = document.documentElement.clientWidth;
 }
 else if( document.body &&  document.body.clientWidth  ) {
	myWidth = document.body.clientWidth; 
 }
 return myWidth;
} 

// retourne la hauteur de la fenêtre du navigateur
function hauteur_fenetre()
{
 if( typeof( window.innerHeight ) == 'number' ) {
	myHeight = window.innerHeight;
 }
 else if( document.documentElement && document.documentElement.clientHeight  ) {
	myHeight = document.documentElement.clientHeight;
 }
 else if( document.body && document.body.clientHeight ) {
	myHeight = document.body.clientHeight;
 }
 return myHeight;
}

// permet de garantir que l'overlay est bien a sa place.
function grisageFenetre()
{
	
	var widNav = largeur_fenetre() + getScrollX(); 
	var widGlobal = $('global').getWidth();
	var heiNav = hauteur_fenetre() +getScrollY(); 
	var heiGlobal = $('global').getHeight();
	
	var wid; var hei;
	if (widNav > widGlobal) wid = widNav; else wid = widGlobal;
	if (heiNav > heiGlobal) hei = heiNav; else hei = heiGlobal;
	/*var margin = wid - 1024;
	if (margin < 0) margin=0;
	wid = wid + margin;*/
	wid = widNav;
	hei = heiGlobal;
	
	$('overlay').setStyle({
		//'margin-left': '-'+margin+'px',
		width: wid+'px',
		height: hei+'px'
	});
	$('overlay').setOpacity(0.4);
	$('overlay').show();
}

function getScrollX() 
{
  var scrOfX = 0;
  if( typeof( window.pageXOffset ) == 'number' ) {
	//Netscape compliant
	scrOfX = window.pageXOffset;
  } else if( document.body &&  document.body.scrollLeft  ) {
	//DOM compliant
	scrOfX = document.body.scrollLeft;
  } else if( document.documentElement &&  document.documentElement.scrollLeft  ) {
	//IE6 standards compliant mode
	scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfX;
}

function getScrollY() 
{
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
	//Netscape compliant
	scrOfY = window.pageYOffset;
  } else if( document.body &&  document.body.scrollTop ) {
	//DOM compliant
	scrOfY = document.body.scrollTop;
  } else if( document.documentElement &&  document.documentElement.scrollTop  ) {
	//IE6 standards compliant mode
	scrOfY = document.documentElement.scrollTop;
  }
  return  scrOfY ;
}
