function init() // ecrase la fonction init originelle
{
  if(!window.imajour) imajour = 0;
  // Rq: ci-dessous les objets photo sont recrees une deuxieme fois
  album = new Album(_i);
  _i = null;

  diapoData = new Array( album, image_index, 'petit', 0, 5000, 1);
  diapo = new Diaporama(diapoData); 
//  display_start();  

// start==photo
if(
  document.getElementById('indexDiv').style.display!=document.getElementById('photoDiv').style.display
  && document.getElementById('photoDiv').style.display=='block'
){
    if(document.getElementById('descDiv')){
    document.getElementById('descDiv').style.display='none';
    }
    if(document.getElementById('optionsDiv')){
    document.getElementById('optionsDiv').style.display='none';
    }

}

  if(document.all && window.photo) {
    changeTrans("fade", photo); //fade, slide ou randomdissolve  
  }

//  alert(image_index);
  //diapo.display(image_index);
  display_photo(image_index);
}
function display_photo(i)
{
  i=i*1;
  var first_val = offset; 
  var last_val = offset+limit-1;	 
  if(last_val > (nb_images-1)){ // dernière image de l'album si nb_images%limit!=0
    last_val = nb_images-1;
  }
  var first_offset = 0;
  var nb_pages = nb_images/limit;
  if(nb_pages > Math.floor(nb_pages)){
    nb_pages = Math.floor(nb_pages)+1;
  }
  var last_offset = limit*(nb_pages-1);
//alert('i='+i+', first_val='+first_val+', last val='+last_val+', first_offset='+first_offset+', last offset='+last_offset);
  if(i>last_val || i<first_val){
    if(i>last_val){
      if(i>last_offset){
        i = 0;
        offset = first_offset;
      }else{
        offset = i; //first_val + limit
      }
    }else if(i<first_val){
      if(i<first_offset){
        i = nb_images - 1;
        offset = last_offset;
      }else{
        offset = first_val - limit;
      }
    }
    if(nb_images>limit){ // pagination
      //&start=photo => construire planche contact '&ImageINDEX='+i+
  //    alert('index.php?SiteID='+site_id+'&PageID='+page_id+'&AlbumID='+album_id+'&offset='+offset+'&limit='+limit);
      show_waiting();
      location.href='index.php?SiteID='+site_id+'&PageID='+page_id+'&AlbumID='+album_id+'&offset='+offset+'&limit='+limit+'&start=photo';
      return;
    }    
  }
  diapo.display(i);
  //if(nb_images>limit){ // pagination
    // Repositionne la liste des images sur le bon index (popslide)
    if(document.choix && document.choix.listimage) {
      for(var j=0; j<document.choix.listimage.options.length; j++){
  	if(document.choix.listimage.options[j].value == i){
          document.choix.listimage.selectedIndex=j;	  
          break;
        }
      }
//      document.choix.listimage.selectedIndex=i-offset;
    }
  //}
}
function show_waiting()
{
  if(!window.waiting){
    return;
  }
  waiting.show();
}
function px_display(index)
{
  if(!window.diapo){
    return;
  }
  if(document.getElementById('indexDiv').style.display!=document.getElementById('photoDiv').style.display){
    document.getElementById('indexDiv').style.display='none';
    if(document.getElementById('descDiv')){
    document.getElementById('descDiv').style.display='none';
    }
    if(document.getElementById('optionsDiv')){
    document.getElementById('optionsDiv').style.display='none';
    }
    document.getElementById('navDiv').style.display='block';
    document.getElementById('photoDiv').style.display='block';
    tt_Hide();
  }
  //diapo.display(index);
  display_photo(index);
  safari_show(index);
  return;
}
function index_display()
{
  if(document.getElementById('indexDiv').style.display!=document.getElementById('photoDiv').style.display){
    if(document.getElementById('descDiv')){
      document.getElementById('descDiv').style.display='block';
    }
    if(document.getElementById('optionsDiv')){
    document.getElementById('optionsDiv').style.display='block';
    }
    document.getElementById('indexDiv').style.display='block';
    document.getElementById('navDiv').style.display='none';
    document.getElementById('photoDiv').style.display='none';
  }
  return;
}
function updateStylesheets() {
	var i,a,s;
	a=document.getElementsByTagName('link');
	for(i=0;i<a.length;i++) {
		s=a[i];
		if(s.rel.toLowerCase().indexOf('stylesheet')>=0&&s.href) {
			var h=s.href.replace(/(&|\\?)forceReload=d /,'');
			s.href=h+(h.indexOf('?')>=0?'&':'?')+'forceReload='+(new Date().valueOf());
		}
	}
}
function grand_format()
{
  // a terme remplacer album_id par album.id
  full_screen('PageID=57&AlbumID='+album_id+'&ImageINDEX='+diapo.album.get_current_index()+'&display=1','diaposcope');
}
function d_prev()
{
/*
  var len = document.choix.listimage.options.length;
  //var i = document.choix.listimage.options[document.choix.listimage.selectedIndex].value;
  var i = document.choix.listimage.selectedIndex;
  diapo.display(i==0?len-1:i-1);
  safari_show(i==0?len-1:i-1);
*/
  var i = diapo.album.get_current_index();
  display_photo(i-1);
}
function safari_show(index)
{
  var detect = navigator.userAgent.toLowerCase();
  var is_safari = detect.indexOf('safari') + 1;
  if(!is_safari){
    return;
  }
  waiting.hide();
  diapo.display(index+1);
  waiting.hide();
  diapo.display(index);
  waiting.hide();
  //photo.show();
}
function d_next()
{
/*
  var len = document.choix.listimage.options.length;
  var i = document.choix.listimage.selectedIndex;
  diapo.display(i==len-1?0:i+1);
  safari_show(i==len-1?0:i+1);
*/
  //var i = document.choix.listimage.options[document.choix.listimage.selectedIndex].value;
  var i = diapo.album.get_current_index();
  display_photo(i+1);
}