// JavaScript Document
function ParcoursTexte() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("texte")) return false;	
	var lien=new String();
	idTexte=document.getElementById('texte');
	liens=idTexte.getElementsByTagName('a');
	var tableau=new Array();
	for (i=0;i<liens.length;i++) {
		lien=liens[i].href;									   
		extension=lien.substr(lien.lastIndexOf('.')+1,10);
		if (extension=='jpg') {
			tableau.push(lien);
			liens[i].onmouseover=function () {AfficheImage(this.href,true)};
			liens[i].onmouseout=function () {EffaceImage()};
		}
	}
	D=document;
	ie=D.all?1:0;
	op=window.opera?1:0;
	dtd= D.compatMode=="CSS1Compat"?1:0;
	ob=D;
	db=ie&!op&&dtd?D.documentElement:D.body; //exception IE6 dtd
	D.onmousemove=bouge;
	simplePreload(tableau);
}

function bouge(e){ // suit la souris
	sx=ie?db.scrollLeft:pageXOffset;     //scroll h
	sy=ie?db.scrollTop:pageYOffset;      //scroll v
	px=ie?event.clientX+sx:e.pageX;      //curseur x
	py=ie?event.clientY+sy:e.pageY;      //curseur y
}

function AfficheImage(lien,first) {
	var affiche=document.getElementById('afficheimage');
	with(affiche.style){
		position="absolute";
		right=30+"px";
		top=30+"px";
		display='block';
		visible=true;
	}
	var text='';
	for (i=0;i<document.imageArray.length;i++) {
		if (document.imageArray[i].src=lien) {
			niveau=i;	
		}
	}
	if (document.imageArray[niveau].complete) {
		affiche.innerHTML='<div style="border: 4px #FF7401 solid;padding: 2px;background-color: #000000;color: #FFFFFF;">'+redimImage(lien,document.body.clientWidth-px-60,py-30)+'</div>';
	} else {
		affiche.innerHTML='<div style="border: 4px #FF7401 solid;padding: 2px;background-color: #000000;color: #FFFFFF;">Chargement en cours...</div>';
	}
}

function EffaceImage(lien) {
	var affiche=document.getElementById('afficheimage');
	affiche.innerHTML='';
	affiche.style.visible=false;
}

function redimImage(inImg, inMW, inMH) {
  var maxWidth = inMW;
  var maxHeight = inMH;
  var dW = 0;
  var dH = 0;
  var oImg = new Image();
  oImg.src = inImg;
  var h = dH = oImg.height;
  var w = dW = oImg.width;
  if ((h >= maxHeight) || (w >= maxWidth)) {
    if ((h >= maxHeight) && (w >= maxWidth)) {
      if (h > w) {
        dH = maxHeight;
        dW = parseInt((w * dH) / h, 10);
      } else {
        dW = maxWidth;
        dH = parseInt((h * dW) / w, 10);
      }
    } else if ((h > maxHeight) && (w < maxWidth)) {
      dH = maxHeight;
      dW = parseInt((w * dH) / h, 10);
    } else if ((h < maxHeight) && (w > maxWidth)) {
      dW = maxWidth;
      dH = parseInt((h * dW) / w, 10);
    }
  }
  return ("<img src=\"" + inImg + "\" width=\"" + dW + "\" height=\"" + dH + "\" style=\"border: 2px #FFC501 solid;\">");
};

// Example:
// simplePreload( '01.gif', '02.gif' ); 
function simplePreload(tableau) { 
  window.status='Préchargement ('+tableau.length+' images)...';
  document.imageArray = new Array(tableau.length);
  for (var i=0; i<tableau.length; i++) {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = tableau[i];
  }
}

