
// taille de la fenêtre
var screenWidth,screenHeight;
function screenSize() {
    if (self.innerHeight) // all except Explorer
    {
    	screenWidth = self.innerWidth;
    	screenHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    	// Explorer 6 Strict Mode
    {
    	screenWidth = document.documentElement.clientWidth;
    	screenHeight = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
    	screenWidth = document.body.clientWidth;
    	screenHeight = document.body.clientHeight;
    }
}

function getHeight(id) {
    var o=document.getElementById(id);
    if (!o) return false;
    return o.offsetHeight;
}

function setHeight(id, height) {
    var o=document.getElementById(id);
    if (!id) return false;
    if (!height) return false;
    o.style.height=height;
}

function fixObject(id) {
    var o=document.getElementById(id);
    if (!o) return;
    var width=o.offsetWidth;
    var height=o.offsetHeight;
    o.style.width=width;
    o.style.height=height;
}

function whenResize() {
    fitIframe();
}
window.onresize=whenResize;

function fixScreen() {
    screenSize();
    // pour IE il faut réparer le outflow sur la barre de vignettes en cas d'index
    if (document.all) {
        var thumbs=document.getElementById('thumbs');
        var outthumbs=document.getElementById('outthumbs');
        if (!thumbs || !outthumbs) return;
        //thumbs.style.display='none';
        // outthumbs.style.width = "100%";
        var width= screenWidth - 250; // +50 constaté mais pas expliqué
        /* alert(width); */
        outthumbs.style.width=width + "px"; 
        thumbs.style.display='block';
        return;
    }

    var side=document.getElementById("side");
    if (side) side.style.display="none";
    var content=document.getElementById("content");
    if (content) content.style.display="none";
    var o=document.getElementById('container');
    // met un délai
    window.status = ("height " + screenHeight + " " + o.offsetHeight);
    var height=getHeight("outside");
    if (height) side.style.height=height - 20; // prévoir le padding
    side.style.display="block";
    var height=getHeight("outcontent");
    if (height) content.style.height=height; // prévoir le padding
    content.style.display="block";
    /*
    o.style.width=screenWidth;
    o.style.height=screenHeight;
    id='left';
    var o=document.getElementById(id);
    if (!o) return;
    o.style.height=screenHeight;
    id='right';
    var o=document.getElementById(id);
    if (!o) return;
    o.style.height=screenHeight;
    */
}

function fitside() {
    if (document.all) return;
    var outside=document.getElementById('outside');
    if (!outside) return;
    var height=outside.offsetHeight - 50;
    // fixer la hauteur absolue s'il on a pu avoir une valeur acceptable (attention pas de braquets)
    outside.style.height=height;
}

function fitpdf() {
    var pdf=document.getElementById("pdf");
    if (!pdf);
    else if (!document.all);
    else {
        pdf.style.width=width;
        pdf.style.height=height;
    }
}

// hack pour height 100% de l'iframe    
function fitIframe() {
    // get heigth of window
    if (self.innerHeight) frameHeight = self.innerHeight;
    else if (document.documentElement) frameHeight = document.   documentElement.clientHeight;
    else if (document.body) frameHeight = document.body.clientHeight;
    // get height of body
    if(document.body) bodyHeight=document.body;
    else if(document.documentElement) bodyHeight=document.documentElement;
    if(bodyHeight.scrollHeight) bodyHeight=bodyHeight.scrollHeight;
    else if(bodyHeight.offsetHeight) bodyHeight=bodyHeight.offsetHeight;
    
    if (frameHeight == bodyHeight ) return true;
    if (!document.getElementById) return false;
    
    
      var pdf=document.getElementById('pdf');
      if (pdf == null) return false;
      
      // la notice qui pourrait être trop grande
      var side=document.getElementById('side');
      if (side == null) return false;
      side.style.display='none';
    // changer quelque chose pour faire calculer
      pdf.parentNode.style.padding=0;
      // récupérer la taille de l'iframe sans la notice trop longue
      var height=pdf.offsetHeight;
      // fixer la hauteur absolue s'il on a pu avoir une valeur acceptable (attention pas de braquets)
      if(height != 0 ) pdf.style.height=height;
      
      // rafficher la notice
      side.style.display='';
      return true;
}


function fitright() {
    var right=document.getElementById('right');
    if (!right) return;
    var width=right.offsetWidth;
    // fixer la hauteur absolue s'il on a pu avoir une valeur acceptable (attention pas de braquets)
    right.style.width=width;
}

function getParameter(name) {
    var value=null;
    if (!name) return value;
    var search=window.location.search;
    if (!search) return value;
    if (search.charAt(0)=='?') search=search.substr(1);
    if (search.indexOf(name) == -1) return value;
    search=search.substr(search.indexOf(name) + name.length);
    if (search.charAt(0)!='=') return value;
    search=search.substr(1);
    if (search.indexOf('\u0026') == -1) return search;
    return value=search.substring(0, search.indexOf('\u0026'));
}


function fitcontent() {
    if (document.all) return;
    var content=document.getElementById('content');
    if (!content) return;
    var height=content.offsetHeight - 30;
    content.style.height=height;
    content.style.top=0;
}

/* fonction pour une notice au survol */

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

/*
Pour une fenêtre au survol
*/
function show(evt,id){
	if (!document.getElementById) return;
	obj = document.getElementById(id);
	// pas trouvé l'objet, on laisse couler l'événement
	if(!obj || !obj.style) return true;

	// prendre le point du pointeur
	if (evt.pageY) { //Calculates the position for Navigator 4
		y = evt.pageY;
		x = evt.pageX;
	} else if (evt.y) { // Calculates the position for IE4
		y = /* getViewY() + */ evt.y; 
		x = /* getViewX() + */ evt.x;
	}
	
	// alert("x="+x+" y="+y);
	
	// prendre la taille générale de la fenêtre
	var width=(screenWidth)?screenWidth:1000;
	var height=(screenHeight)?screenHeight:800;
	
	/*
    // horizontal, si trop à  droite
	if (x > (width * 0.7)) {
		obj.style.left=x - obj.offsetWidth + 100;
	} // horizontal, dans la premiÃ¨re moitié, aligné sur la droite du pointeur
	if (x < (width * 0.5) && x > 200) {
		obj.style.left=10 + "px";
		obj.style.width= (x - 30) ;
	} // si plutôt à  gauche
	else obj.style.right = x; 
	*/
	
	// vertical, s'il n'y a pas la place d'afficher l'objet, on aligne sur le bas
	// obj.style.bottom=getViewY(); // ne pas oublier la hauteur de scroll
	var scrollY=getScrollY();
	var scrollX=getScrollX();
	/*
	if ( obj.offsetHeight > (height - y) ) {
		obj.style.top=y - 20 - obj.offsetHeight + getViewY(); // ne pas oublier la hauteur de scroll
	} // si plutôt haut
	else if (y > (height * 0.7)) {
		obj.style.top=y - obj.offsetHeight - 20 + getViewY(); // ne pas oublier la hauteur de scroll
	} // si plutôt haut
	else {
		obj.style.top = y + getViewY(); // ne pas oublier la hauteur de scroll
	} */
	
	// rendre visible et sécuriser le délai
	setDelay(obj);
	// positionnner au mieux la fenêtre
	window.status= "" + id 
        + " x="+x 
        + " y="+y
        + " scrollX="+ scrollX 
        + " scrollY=" + scrollY
        + " width=" + width
        + " height=" + height
        + " left=" + obj.style.left
        + " right=" + obj.style.right
        + " objWidth="+ obj.style.width
    ;
	return false;
}

/*
var toHide;
function hide(id) {
	if (toHide && toHide.style) {
        toHide.style.visibility = "hidden";
        toHide.style.display="none";
    }
	if (!document.getElementById) return;
	obj = document.getElementById(id);
	if (obj && obj.style) {
        // obj.style.visibility = "hidden";
        obj.style.display="none";
    }
	return false;
}
*/

var toHide;
function setDelay(obj) {
	// s'il y avait un objet en mémoire, on le cache
	if (toHide && toHide != obj && toHide.style) {
		toHide.style.visibility = "hidden";
	}
	obj.style.visibility="visible";
	toHide=obj;
	toHide.wait=true;
}

var delay = 500;
function hide(id) {
	if(!toHide) return;
	toHide.wait=null;
	setTimeout('if (toHide && !toHide.wait) { toHide.style.visibility="hidden"; toHide=null; }', delay);
}

/*

var x,y;
if (self.pageYOffset) // all except Explorer
{
	x = self.pageXOffset;
	y = self.pageYOffset;
}
else if (document.documentElement && document.documentElement.scrollTop)
	// Explorer 6 Strict
{
	x = document.documentElement.scrollLeft;
	y = document.documentElement.scrollTop;
}
else if (document.body) // all other Explorers
{
	x = document.body.scrollLeft;
	y = document.body.scrollTop;
}

*/


function getScrollX(){
  var offset=0;
  if (window.pageXOffset) offset=window.pageXOffset; // gecko, nn4,opera
  else if (document.documentElement &&
	document.documentElement.scrollLeft)
	offset=document.documentElement.scrollLeft; // ie6 compat mode
  else if (document.body && document.body.scrollLeft)
	offset=document.body.scrollLeft; // ie4up
  return offset;
}

function getScrollY(){
  var offset=0;
  if (window.pageYOffset) offset=window.pageYOffset;
  else if (document.documentElement &&
	document.documentElement.scrollTop)
	offset=document.documentElement.scrollTop;
  else if (document.body && document.body.scrollTop)
	offset=document.body.scrollTop;
  return offset;
}



function pngfix () {
	// ce commentaire ne sera exÃ©cutÃ© que par IE
  /*@cc_on @*/
  /*@if(true)
  for(var i=0; i<document.images.length; i++) {
		var img = document.images[i];
		if (!img.src) continue;
		// on ne prends que les images en icones, dÃ©conne avec les images en display:none
		if (img.className != 'icon') continue;
		// not a a png img
		if (img.src.toUpperCase().search(/\.PNG$/) == -1 ) continue;
		if (img.height) img.style.height=img.height;
		// the ugly IE hack
		img.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader('
					+ 'src=\'' + img.src + '\''
					+ ', sizingMethod=\'scale\''
				+ ')';
		// and now, hide orginal image
    img.src=img.src.replace(/\/[^\/]*$/, "/x.gif");
		// img.style.visibility='hidden';
  }
   @*/
/*@end @*/
}

