
function boxdiaporama ( name ) {
    /* vars */
    this.selected = 0;
    this.name = name;
    this.basename = 'bd_'+name+'_';
    this.imgs = new Array();
    this.imgs2 = new Array();
    this.alts = new Array();
    this.descs = new Array();
    this.imageLoader = null;
    
    /* methods */
    this.addImage = boxdiaporama_addImage;
    this.select = boxdiaporama_select;
    this.open = boxdiaporama_open;
    this.close = boxdiaporama_close;
    this.displayImage = boxdiaporama_displayImage;
    this.checkImageLoad = boxdiaporama_checkImageLoad;
    
    /* test methods */
    this.isSelected = boxdiaporama_isSelected;
}

function boxdiaporama_addImage ( path, path2, alt, desc ) {
    this.imgs[this.imgs.length] = path;
    this.imgs2[this.imgs2.length] = path2;
    this.alts[this.alts.length] = alt;
    this.descs[this.alts.length] = desc;
}

function boxdiaporama_select ( idx ) {
    document.getElementById(this.basename+this.selected).className="box_diaporama";
    this.selected = idx;
    if ( idx == 0 ) {
      document.getElementById(this.basename+this.selected).className="box_diaporama_fsel";
    } else if ( idx == this.imgs.length-1 ) {
      document.getElementById(this.basename+this.selected).className="box_diaporama_lsel";
    } else {
      document.getElementById(this.basename+this.selected).className="box_diaporama_sel";
    }
    document.getElementById(this.basename+'img').src=this.imgs[idx];
    document.getElementById(this.basename+'img').alt=this.alts[idx]; 
}

function boxdiaporama_open ( diapo ) {
  this.imageLoader = new Image();
  this.imageLoader.src = this.imgs2[this.selected];
  document.getElementById(this.basename+'mainimg').src = this.imageLoader.src;
  document.getElementById(this.basename+'mainimg').alt = this.alts[this.selected];
  document.getElementById(this.basename+'text').innerHTML = this.alts[this.selected];
  this.checkImageLoad();   
}

function boxdiaporama_close ( diapo) {
    document.getElementById(this.basename+'blocMain').style.visibility = "hidden";
}

function boxdiaporama_isSelected ( id ) {
  return ( this.selected == id );
}

function boxdiaporama_checkImageLoad ( ) {
    if ( this.imageLoader.complete ) {
        this.displayImage();
    } else {
         setTimeout( this.name+'.checkImageLoad()', 100 );
    }
}

function boxdiaporama_displayImage ( ) {
  var image = document.getElementById(this.basename+'mainimg');
  var content = document.getElementById(this.basename+'blocMain');
  var text = document.getElementById(this.basename+'text');
  image.src = this.imageLoader.src;
  image.alt = this.alts[this.selected];
  text.innerHTML = this.alts[this.selected];    
  var win = window.open("about:blank", "win", "innerwidth=" + (image.width + 30) + ", innerheight=" + (image.height + 90) + ", dependent=yes,location=no,menubar=no,status=no,toolbar=no,scrollbars=yes, resizable=yes");
  win.document.write('<html><title>Phototèque</title><body style="margin:0px;">');
  win.document.write(content.innerHTML);
  win.document.write('</body></html>');
}
