var xhr = null; 

function getXhr(){
	if(window.XMLHttpRequest) // Firefox et autres
	   xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
	   try {
                xhr = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
	}
	else { // XMLHttpRequest non supporté par le navigateur 
	   alert("Your navigator does not support the XMLHTTPRequest objects ..."); 
	   xhr = false; 
	} 
}

function chargement() {
  $('charge').setHTML('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Chargement');
  var instance = new Fx.Styles($('charge'), {duration: 50});
  instance.custom({'top': [-40,0]});
}

function chargementFin() {
  var instance = new Fx.Styles($('diapo'), {duration: 300});
  instance.custom({'opacity': [0,1]});
  var instance2 = new Fx.Styles($('charge'), {duration: 200});
  instance2.custom({'top': [0,-40]});
}

function diapo(n,m) {
var maxWidth = 519;
var maxHeight = 329; 
chargement();
$$('.vign').setStyles('border-color: #2F2F2F;');
$('vign_' + n).setStyles('border-color: #A347A4;');
   getXhr()
    xhr.onreadystatechange = function(){
    if(xhr.readyState == 4 && xhr.status == 200){
    dim = xhr.responseText;
    dim = dim.split(";");
    largeur = dim[0];
    hauteur = dim[1];
    if ((hauteur > maxHeight) || (largeur > maxWidth)) {
      if (largeur > hauteur) {  
          if (parseInt((hauteur * maxWidth) / largeur, 10) <= maxHeight) {
          hauteur = parseInt((hauteur * maxWidth) / largeur, 10);
          largeur = maxWidth;
          maxHeight = hauteur;
          }
          else {
          largeur = parseInt((largeur * maxHeight) / hauteur, 10);
          hauteur = maxHeight;     
          }
      }
      else {
      largeur = parseInt((largeur * maxHeight) / hauteur, 10);
      hauteur = maxHeight;
      }
    }
    if (m == "") {
    $('visu').setHTML('<img src="doc/diapo/' + n + '.jpg" width="' + largeur + '" height="' + hauteur + '" onload="chargementFin();" alt="diapo" id="diapo" />');    
    }
    else {
    $('visu').setHTML('<img src="doc/diapo/WaterMark2.php?img=' + n + '.jpg&copyright=' + m + '" width="' + largeur + '" height="' + hauteur + '" onload="chargementFin();" alt="diapo" id="diapo" />');    
    }
    }
    }
    xhr.open("POST","photo.php",true);
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhr.send("image=" + n);
}

var test_desc=0;
function affiche_infos() {
  if (test_desc==0) {
  var instance = new Fx.Styles($('infos_contenu'), {duration: 200});
  instance.custom({'top': [-480,0]});
  test_desc=1;
  }
  else {
  var instance = new Fx.Styles($('infos_contenu'), {duration: 200});
  instance.custom({'top': [0,-480]});  
  test_desc=0;
  }

}

function fermer_infos() {
  var instance = new Fx.Styles($('infos_contenu'), {duration: 200});
  instance.custom({'top': [0,-480]});
}
