function ChColor(nome, ref) {
  var browser=navigator.appName;
  //var browser=navigator.userAgent;
  //if (browser=="Microsoft Internet Explorer") {
  if (browser!="Microsoft Internet Explorer") this.ie=false;
  else this.ie=true;

  this.nome=nome;
  this.ref=ref;
  this.su=0;
  this.giu=0;
  this.opacity=0;
  this.opUp=function()
   {
    clearTimeout(this.giu);
    var id=this.ref;
    var elemento=prendiElementoDaId(this.ref);
    opt=this.opacity;
    if(opt<1) {
      this.opacity+=0.05;  
      if(!this.ie) elemento.style.opacity=this.opacity; 
      else elemento.filters.alpha.opacity=opt*100; 
      this.su=window.setTimeout(this.nome+".opUp()", 1);
    }
    else clearTimeout(this.su);
  }
  
  this.opDown=function()
  {
    clearTimeout(this.su);
    var id=this.ref;
    var elemento=prendiElementoDaId(this.ref);
    opt=this.opacity;
    if(opt>0) {
      this.opacity-=0.05; 
      if(!this.ie) elemento.style.opacity=this.opacity; 
      else elemento.filters.alpha.opacity=opt*100; 
      this.giu=window.setTimeout(this.nome+".opDown()", 1);
    }
    else clearTimeout(this.giu);
  }
}
var imageloaded=new ChColor("imageloaded", "imageloaded");
var mainimage=new ChColor("mainimage", "mainimage");
function loadImage(id) {
  elemento=prendiElementoDaId("imageloaded");
  loading=prendiElementoDaId("mainimage");
  ajax = assegnaXMLHttpRequest();
  var param="id="+id;
  nomeFile="/mainimage.php";
  usaLink = true;
  if(ajax) {
    usaLink = false;
    ajax.open("get", nomeFile+"?"+param, true);
    ajax.setRequestHeader("connection", "close");
    ajax.onreadystatechange = function() {
      if(ajax.readyState === 4) {
        if(ajax.status === 200) {
          //elemento.style.backgroundImage = ajax.responseText;
          //elemento.style.backgroundImage = "url(images/io.jpg)";
          imageloaded.opUp();
          mainimage.opDown();
          loading.style.backgroundImage = "none";
        }
        else {
          //elemento.innerHTML = "Impossibile effettuare l'operazione richiesta.<br />";
          //elemento.innerHTML += "Errore riscontrato: " + statusText[ajax.status];
        }
      }
    }
    ajax.send(null);
  }
}

