var LargeurDispo = 0, HauteurDispo = 0;
var ContentHeight = '';
var TimeToSlide = 250.0;
var openAccordion = '';
var openAccordionEncours = 1;
var Compteur = 0;
var NbRun = 0;
var Tempo;
var Tempo2;
//addEventHandler(window, 'resize', windowResize);//pour GoogleMAps
//window.onload = windowLoad; //et pas = windowLoad(); sinon ca ne marche pas !
//window.onresize = windowResize; //et pas = windowResize(); sinon ca ne marche pas !

function runAccordion(index) {
  //alert(index);
  //alert(document.getElementById('GlobalZoneAccordionContainer').style.height);
  var nID = "Accordion" + index + "Content";
  openAccordionEncours = index;
  if (openAccordion == nID) {
    nID = '';
    return;//mettre cette ligne en rem pour avoir la possiblilité de refermer le menu encours (au choix)
  }  
  clearTimeout(Tempo2);
  tempo2 = setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'" + openAccordion + "','" + nID + "')", 33);
  
  openAccordion = nID;
}

function animate(lastTick, timeLeft, closingId, openingId) {  
  ContentHeight =  document.getElementById('GlobalZoneAccordionContainer').style.height;
  ContentHeight = ContentHeight.substr(0, ContentHeight.length - 2);
  ContentHeight = ContentHeight - (NbAccordeon * HauteurUnAccordeon) - CalageAccordeon;

  //alert(ContentHeight);
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  
  var opening = (openingId == '') ? null : document.getElementById(openingId);
  var closing = (closingId == '') ? null : document.getElementById(closingId);
  if(timeLeft <= elapsedTicks) {
    if(opening != null)
      opening.style.height = ContentHeight + 'px';
    
    if(closing != null) {
      closing.style.display = 'none';
      closing.style.height = '0px';
    }
    return;
  }
 
  timeLeft -= elapsedTicks;
  var newClosedHeight = Math.round((timeLeft/TimeToSlide) * ContentHeight);

  if(opening != null) {
    if(opening.style.display != 'block')
      opening.style.display = 'block';
    opening.style.height = (ContentHeight - newClosedHeight) + 'px';
  }
  
  if(closing != null)
    closing.style.height = newClosedHeight + 'px';

  clearTimeout(Tempo2);
  tempo2 = setTimeout("animate(" + curTick + "," + timeLeft +",'" + closingId + "','" + openingId + "')", 33);
}

/* mise en remarque car je devais l'implémenter dans indexjg2.js
function windowLoad(){
  CalculBodyHeight();
  document.getElementById('GlobalZoneAccordionContainer').style.height = HauteurDispo + 'px'
  runAccordion(5);//pour corriger un bug qui ne se produit qu'au chargement de la page
  runAccordion(1);//pour se positionner sur le premier
}
*/

function CalculBodyHeight(){
  LargeurDispo = 0, HauteurDispo = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    LargeurDispo = window.innerWidth;
    HauteurDispo = window.innerHeight;
    }
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    LargeurDispo = document.documentElement.clientWidth;
    HauteurDispo = document.documentElement.clientHeight;
    }
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    LargeurDispo = document.body.clientWidth;
    HauteurDispo = document.body.clientHeight;
    }
  else {
    LargeurDispo = -1;
    HauteurDispo = -1;
    }
    HauteurDispo = HauteurDispo - 25;
  //alert(HauteurDispo);
  /*
  if (navigator.appVersion.indexOf("MSIE")!=-1){
    // IE;
  } else {
    //Autres;
  }
  */
}


/* mise en remarque car je devais l'implémenter dans indexjg2.js
function windowResize(){
  clearTimeout(Tempo);
  clearTimeout(Tempo2);
  Compteur = Compteur + 1
  window.status = Compteur + '>' + NbRun;
  Tempo = setTimeout("ValideRunWindowResize()", 2000); // 1000=1 seconde
}

function ValideRunWindowResize() {
  clearTimeout(Tempo);
  clearTimeout(Tempo2);
  NbRun = NbRun + 1;
  window.status = Compteur + '>' + NbRun;
  Compteur = 0;
  CalculBodyHeight();
  document.getElementById('GlobalZoneAccordionContainer').style.height = HauteurDispo + 'px'
  
  ContentHeight = '';
  TimeToSlide = 250.0;
  openAccordion = '';
  runAccordion(openAccordionEncours);//pour se positionner sur le menu encours avant resize
  
};
*/
