// JavaScript Document

var Clean = 1;
var NoNext = true;
var NoPrev = false;
var Tof = 0;
var Title = 0;
var Load = 0;

function Ajust() {
  maxHeight($('content'));
  var tabImage = $('tabimage');
    if(tabImage){
    tabImage.style.height = hauteur+'px';
    tabImage.style.width = largeur+'px';
  }
  var SquarePhoto = $('square_photo');
    if(SquarePhoto){
    SquarePhoto.style.height = thephoto+'px';
  }
  
}

function Adapt(){  
  GetWindow();
  var TheTof = $('photo');
  if(TheTof){
    if(largeur<900){TheTof.style.height = '300px';}
    else{TheTof.style.height = "";}
    
    ImagesLoader=new Image();
    ImagesLoader.onload = function() {
      setTimeout(function() {
        TheTof.style.marginTop = ((thephoto/2)-(TheTof.offsetHeight/2))+'px';
      },200);
    };
    ImagesLoader.src=TheTof.src;
    
  }
}

function DisplayAll(){

  var AllLinks = $('diapo');
  if(AllLinks){
  
  arrow = $('tabimage').getElementsByTagName('a');
    for (i = 0; i<arrow.length; i++) {
    prevArrow = arrow[0];
    nextArrow = arrow[1];
  } 
  
  var aImg = AllLinks.getElementsByTagName('a');
  var totalImg = aImg.length;
  
    for (i = 0; i<totalImg; i++) {
      aImg[i].onclick = function(){
        Display(this);
        Next(this.id,i);
        Prev(this.id,1);
        $('prev').style.display = (this.id>1)?'inline':'none';
        $('next').style.display = (this.id<totalImg)?'inline':'none';
        return false;
      }
    }

 
    nextArrow.onclick = function(){
      Display(this);
      Next(this.title,totalImg);
      
      factChang = (this.title<totalImg)?2:1;
      Prev(this.title,factChang );
      $('prev').style.display = 'inline';
      return false;
    }

    prevArrow.onclick = function(){
      Display(this);
      Next(this.title,totalImg);
      Prev(this.title,1);
      $('next').style.display = 'inline';
      return false;
    }

    
    function Next(Num,total){
      MNext = (parseInt(Num))+1;
      if(MNext<=total){nextArrow.title = $(MNext).id;}
      else{$('next').style.display = 'none';}
    }

    function Prev(Num,Chang){
      MPrev = (parseInt(Num))-Chang;
      if(MPrev>0){prevArrow.title = $(MPrev).id;}
      else{$('prev').style.display = 'none';}
    }

  }
}

function Display(Lui){
    Tof = $('photo');
    Title = $('title');
    Load = $('loading');
          
    if(Lui.title){
      srcPhoto = $('big'+Lui.title).alt;
      Title.firstChild.nodeValue = Lui.title;}
    else{
      srcPhoto = $('big'+Lui.id).alt;
      Title.firstChild.nodeValue = Lui.id;
    }
    Tof.src = srcPhoto;
    Tof.style.display = "none";
    Load.style.display = "inline";
    Load.style.marginTop = ((thephoto/2)-(Load.offsetHeight/2))+'px';
    
    ImagesLoader=new Image();
    ImagesLoader.onload = function() {
      setTimeout(function() {
        Load.style.display = "none";
        Tof.style.display = "inline";
        Tof.style.marginTop = ((thephoto/2)-(Tof.offsetHeight/2))+'px';
        maxHeight($('content'));
      },200);
    };
    ImagesLoader.src=srcPhoto;
          
    PopUp(srcPhoto);
    
}



function PopUp(MyFile){
 
  var Print = $('print');
  if(Print){
      Print.onclick = function(){
	     Pop(MyFile);
	     return false;
	  }
  }
  
}

function Pop(MyFile){
    GetWindow();
    var xOffset, yOffset;;	  
    xOffset = (largeur - 850)/2;
    yOffset = (hauteur - 500)/2;
    window.open(MyFile,'print','width=850,height=500,screenX='+xOffset
    +',screenY='+yOffset
    +',top='+yOffset
    +',left='+xOffset
    +',scrollbars=yes,resizable=yes,menubar=no');
}
