

//============================================================================
// Copyright (c) 2008 C. Charpentier. All rights reserved.          02.02.2008
//============================================================================


//============================================================================
// affichage ou masquage image zoom
//============================================================================

function ChangeImage( idImage , idTitre, UrlImage , TitImage) {

// -------------------------------------
// début des corrections pour bug IE < 7
// -------------------------------------
// le style position:fixed ne fonctionne pas avec les versions IE < 7
// les instructions suivantes servent a afficher un zoom visible dans la fenetre en cas d'utilisation de l'ascenseur
// sinon le zoom resterait en haut du document et ne pourrait pas etre vu quand on est en bas
  if (versionIE() >= 4 && versionIE() < 7)
    {
// position absolute au lieu de fixed
    document.getElementById( "ZoomImage" ).style.position = "absolute";
// noter la position initiale du zoom (= offsetTop)
    if (this.posTop == undefined) this.posTop = 0;
    if (this.posTop == 0) this.posTop = document.getElementById( "ZoomImage" ).offsetTop;
// deplacer le zoom (= position initiale + scroll ascenseur) 
    if (this.posTop != 0)
      { 
      document.getElementById( "ZoomImage" ).style.pixelTop = this.posTop + (document.documentElement.scrollTop+document.body.scrollTop);
      }
    }
// -------------------------------
// fin des corrections pour bug IE
// -------------------------------

// pas d'image (transparente) ni titre (blanc)
  if (UrlImage == '') {
    document.getElementById( idImage ).src = "images/commun/transparent.gif";
    document.getElementById( idTitre ).innerHTML = "&nbsp;";
//    document.getElementById( idTitre ).style.background = "transparent";
  }

  else {

// position du premier slash
    PosSlash = TitImage.indexOf('/');

// pas de slash : garder le titre inchange
    if (PosSlash == -1)
    { 
      Titre = TitImage;
    }
// si slash : garder le debut du titre (jusqu'au slash) en gros caracteres puis la suite en plus petits (style=suitetitre) en allant a la ligne a chaque slash
    else
    { 
      DebTitre = TitImage.substr(0,PosSlash);
      FinTitre = TitImage.substr(PosSlash+1);
      Titre = DebTitre + "<div class=suitetitre>" + FinTitre.replace(RegExp("/", "g"), "<br>") + "<\div>" ;
    }

    document.getElementById( idImage ).src = UrlImage;
    document.getElementById( idTitre ).innerHTML = Titre;
//    document.getElementById( idTitre ).style.background = "white";
  }
}


//============================================================================
// version IE (ou 0 si pas MSIE)
//============================================================================

function versionIE() {
  ieversion = 0;
  if (navigator.appVersion.indexOf("MSIE") != -1)
    {
    t = navigator.appVersion.split("MSIE") 
    ieversion = parseFloat(t[1]);
    }
  return ieversion;
}


//============================================================================
// largeur actuelle de la fenetre (selon navigateur)
//============================================================================

function getWindowWidth() {

// internet explorer
  if (versionIE() > 0)
    {
    width = document.body.offsetWidth;
    }
// autres navigateurs
  else
    {
    width = window.innerWidth;
    }
  return width;
}



//============================================================================
// jouer un son swf
//============================================================================

function PlaySound(objSon) {

// l'objet son est defini dans header : new FlashSound( )
// la fonction gotoAndPlay est definie dans flashsound.js
// le son swf a executer est defini par la fonction customEmbedSWF
// la conversion depuis wav est faite avec la commande suivante :
// "C:\Program Files\Swftools\wav2swf.exe"   -o son.swf son.wav -S

  cmdSound = objSon + ".gotoAndPlay('/', 1)";
  eval(cmdSound);
  return;
}



//============================================================================
// encryptage e-mail
//============================================================================

function decode(s) {
  r='';
  for(i=0;i<s.length;i++){n=s.charCodeAt(i);if (n>=8364) {n = 128;} r += String.fromCharCode( n - 4 ); }
  return r;
}

function ChangeLink() {
  var a ="qempxs";
  var m='%40';d=unescape(m);
  var nomfin = "pentier";
  var nomdeb = "corina.char";
  var domfin = ".fr";
  var domdeb = "yahoo";
  var aro = nomdeb + nomfin + d + domdeb + domfin;
  var newLink = decode(a) + ':' + aro + '?' + 'subject=' + document.title;
  document.getElementById("idLink").href = newLink;
}


//============================================================================
// chronometre
//============================================================================

function chrono()
  {
  secon++; //incrementation des secondes de 1
  if (secon>59){secon=0;minu++} //si secondes > 59, on les reinitialise a 0 et on incremente les minutes de 1
  if (minu>99){minu=0;}         //si minutes > 99, on les reinitialise a 0 (affichage sur 2 positions seulement)

  document.images["chromin1"].src = "images/commun/lcd" + ((minu - minu % 10) / 10) + ".png";
  document.images["chromin2"].src = "images/commun/lcd" + (minu % 10) + ".png";

  document.images["chrosec1"].src = "images/commun/lcd" + ((secon - secon % 10) / 10) + ".png";
  document.images["chrosec2"].src = "images/commun/lcd" + (secon % 10) + ".png";

  if (chronosto)
    {
    document.getElementById( "chromin1" ).style.cursor = "pointer";
    document.getElementById( "chromin2" ).style.cursor = "pointer";
    document.getElementById( "chrosec1" ).style.cursor = "pointer";
    document.getElementById( "chrosec2" ).style.cursor = "pointer";

    document.getElementById( "chromin1" ).title = chronopau;
    document.getElementById( "chromin2" ).title = chronopau;
    document.getElementById( "chrosec1" ).title = chronopau;
    document.getElementById( "chrosec2" ).title = chronopau;

    chronosto = false;
    }

  compte=setTimeout('chrono()',1000); //la fonction est relancee tous les secondes
  }

function chronopause(fonction)
  { 
  chronostop(); 
  if (fonction == "puzzle") testPuzzleOK(-9);
  if (fonction == "taquin") myTaquin.stopchrono();
  }


function chronostop()
  { 

  document.getElementById( "chromin1" ).style.cursor = "default";
  document.getElementById( "chromin2" ).style.cursor = "default";
  document.getElementById( "chrosec1" ).style.cursor = "default";
  document.getElementById( "chrosec2" ).style.cursor = "default";

  document.getElementById( "chromin1" ).title = chronomin;
  document.getElementById( "chromin2" ).title = chronomin;
  document.getElementById( "chrosec1" ).title = chronosec;
  document.getElementById( "chrosec2" ).title = chronosec;

  if (!(chronosto))
    { 
    clearTimeout(compte); //arrete la fonction chrono()
    chronosto = true;
    }
  }


//============================================================================
// Creation d'une animation
//============================================================================

  function CreatAnimation(img,width,height,delai,looponce)
  {
    document.write('<img style="position:absolute;" name="animat" src="' + img + '" width=' + width + 'height=' + height + '> ');

    SET_DHTML("animat"+CURSOR_HAND);

    animat_iW = dd.getWndW();
    animat_obj = dd.elements["animat"];
// redonner a l'animation sa taille normale (= 0 depuis leur insertion (width=height=0) ci-dessus)
    animat_obj.resizeTo(width,height) ;

// attendre un peu avant de demarrer l'animation (delai en secondes a transformer en milli-secondes) 
    setTimeout("javascript:ANIM('start')", (delai * 1000));


  }


function ANIM(action)
{
  if (action == null)
  {
    if(!dd.obj || !dd.op6)
    {
// pour recommencer avec une image qui ne deborde pas :
      newx = animat_obj.x<=-animat_obj.w? animat_iW - 20 : (animat_obj.x - 5);

// animat_x_depart pas toujours bien alimente sur fonction start (bug dd ?)
      if (animat_x_depart < 100) animat_x_depart = animat_obj.defx;

// s'arreter quand on a fait un tour complet
      if (animat_obj.x > animat_x_depart && newx <= animat_x_depart)
      {
        ANIM("stop");
      }
      else
      {
        animat_obj.moveTo(newx,animat_obj.y);
        this.time = setTimeout("ANIM()", 50);
      }
    }
  }

// demarrer animation
  else if (action == "start")
  {
    this.animStarted = true;
    animat_x_depart = animat_obj.x;
    this.time = setTimeout("ANIM()", 50);
  }

// arreter animation
  else if (action == "stop")
  {
    this.animStarted = false;
    clearTimeout(this.time);
  }

// debut drag and drop
  else if (action == "drag")
  {
// noter les coordonnees pour detecter les deplacements
    this.x_drag = animat_obj.x;
    this.y_drag = animat_obj.y;
    this.drag_started = true;
  }

// fin drag and drop
  else if ((action == "drop") && (this.drag_started))
  {
    this.drag_started = false;
// si animation en cours ou pas de deplacement par drag (seulement click sur animation arretee) :
    if ((this.animStarted) || ((this.x_drag == animat_obj.x) && (this.y_drag == animat_obj.y)))
    {
// - si animation en cours : l'arreter
      if (this.animStarted)
      {
        ANIM("stop");
      }
// - sinon : la demarrer
      else
      {
        ANIM("start");
      }
    }
  }
}


//============================================================================
// Fonctions personnalisees pour DHTML (wz_dragdrop.js)
//============================================================================

function my_PickFunc()
  {
  ANIM("drag");
  }

function my_DropFunc()
  {
  ANIM("drop");
  }
