
var videoVue = null, formatVideo = null, precedenteVideoVue = null, autoDetectionBandePassante = 1;

function prepareLecture(id) {

  try {
    supprimeChronoLog();
  }
  catch (e) {
    alert('CATCH SUR supprimeChronoLog()');
  }
    
  if ( videoVue ) {
    precedenteVideoVue = videoVue;
    if ( $(videoVue) ) {
      $(videoVue + 'Img').src = "Images/Vignettes/" + videoVue + ".gif";
      $(videoVue).setStyle( { borderColor: '#AB5D2C' } );
    }
  }

  videoVue = id;

  /*
  if ( videoVue == 'pp_cannes2009_day01' )
    $('legende').update('<div style="font-size: 12pt; font-weight: bold">EN 2010<br><img style="float: right;" class="lien" src="Images/majesticStudio.jpg" alt="Majestic Studio" title="Majestic Studio"onclick="window.open(\'majesticStudio.pdf\')"><br>IL EST TEMPS DE RALLUMER LES ETOILES...<br><div style="text-align: right">Guillaume Apollinaire</div><br>Hubert PIERNET et toute son équipe vous souhaite une<div style="text-align: right">BONNE ET HEUREUSE ANNEE</div>                            </div>');
  else
  */
  $('legende').update( eval(videoVue+'_en')  + '<h1 style="text-align: center; font-size: 12pt;">Watch the 2010 issue on:<br><a href="http://www.majestic-studio.net">www.majestic-studio.net</a><br><br></h1><div style="color: white"><h1>Your SD & HD quality videos from the 62<sup>nd</sup> Festival de Cannes</h1><p><a href="http://www.majestic-studio.net"><img style="float: right;" class="lien" src="Images/majesticStudio.jpg" alt="Majestic Studio" title="Majestic Studio"></a>SD & HD quality contents available:</p><ul> <li>On site at the <strong>Majestic</strong> Deauville lounge and at the <strong>Palais</strong>: "Cross-Médias - Prestige Press" production unit see the <a style="color: white" href="contactsFestival.php">[Contacts]</a> tab to reach us.<!-- <li>On line: <a style="color: white" href="http://www.newspusher.com/postSearch_lst.php?keywords=festival+de+cannes&search=Search" target="_blank">www.newspusher.com</a> --> <li>On line: <a style="color: white" href="http://video.tvfestival.tv/EN/channels.html" target="_blank">www.newspusher.com</a></ul></div><!--<p>Essential pictures for your coverage:</p><ul> <li>Stars entering the Festival Palace for the evening screenings (19:30-22:00) of all the official screenings	(Duration : 3m pr-editing) <li>Stars entering the Festival to attend the opening ceremony and the closing ceremony (Duration : 3 m pr-editing) <li>Press Conferences of all the films of the official program (Duration : 5 m per-editing) <li>Duplication of the clips of all the films in the official sections.</ul> --><p>THE WEB TV "CROSSMEDIAS" from May 12, opening day of the Cannes Film Festival, will offer its daily reports including:</p><ul> <li>The "Red Carpet". <li>The Press Conferences of Films in the Official Competition  <li>The "Excerpts and Presentations" of the competing films.  <li>The interviews with celebrities.  <li>Official Evenings  <li>The sketches and News Croisette</ul><p>... and all the information on our productions underway for TV channels</p><p>Close to 35,000 professionals in the Cinema of the world, 4,000 journalists, 350 TV channels will be on the Croisette for 12 days for the most important film event on the planet.</p>' );
  voirVideo();

  if ( $(videoVue) ) {
    $(videoVue).setStyle( { borderColor: '#F3DACB' } );
    $(videoVue + 'Img').src = 'Images/Vignettes/onair114x64.gif';
    $(videoVue).focus();
  }

}


function voirVideo() {
 
 if ( detectFlash() ) {
   joueFlash();
 }
 else {
       $('video').update('<div style="padding: 5px; color: red; background-color: white;"><p>You must have / Vous devez disposer de : <a href="javascript: void(open(\'http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash&Lang=French\'))">Flash Player</a>.</p>');
     }
}


function joueFlash() {
  var largeurVideo = 576
    hauteurVideo = 324 + 20;


  if ( !flash8 ) {
    $('video').update('<div id="pb"> <h1>!!! ATTENTION !!!<br><br>Votre lecteur multimédia Flash est trop ancien !</h1> <p>Pour lire nos vidéos, vous devez disposer d&rsquo;au moins la version 8 du lecteur multimédia Flash. De plus, un lecteur multimédia Flash trop ancien peut présenter un risque de sécurité pour vous.</p> <p style="font-weight: bold;">Nous vous recommandons donc vivement de vous rendre sur <a style="color: #C54639;" href="http://www.adobe.com/go/getflashplayer">le centre de téléchargement</a> du lecteur multimédia Flash.</p> <h1><br>!!!ATTENTION!!!<br><br>Your Flash player is too old.</h1> <p>To watch our videos, you need at least Flash player release 8. Moreover a Flash player too old is not secure to use.</p> <p style="font-weight: bold;">Please <a style="color: #C54639;" href="http://www.adobe.com/go/getflashplayer">update your Flash player</a>.</p></div>');
    return;
  }

  formatVideo = 'FL';
  logueInitial();
  
  if ( $('mediaPlayer') ) { // Le player existe, il suffit donc de juste charger la vidéo !
    $('mediaPlayer').sendEvent('stop'); // stop playing AND BUFFERING !
    // Nécessaire pour MSIE, car sinon il continue à télécharger (buffering) la (les) vidéo(s) précédente(s)

    $('mediaPlayer').loadFile({file:urlVideo()});
  
    // trace pour vérification si besoin !
    /*
  var obj = $('mediaPlayer').itemData( $('mediaPlayer').getLength() - 1 );
  alert(obj.file);
    */

    return;
  }

  
  // Le player vidéo Flash n'existe pas : donc je le crée !
  
  // À présent, je passe par SWFObject pour avoir le nouveau support du PLEIN ÉCRAN...
  // http://www.jeroenwijering.com/extras/readme.html
  //  'http://www.teleavision.net/mediaplayer.swf'
  var so = new SWFObject('mediaplayer.swf.php', 'mediaPlayer', largeurVideo, hauteurVideo,'8');
  so.addParam('allowfullscreen','true');
  so.addVariable('javascriptid','mediaPlayer');
  so.addVariable('width', largeurVideo);
  so.addVariable('height', hauteurVideo);
  so.addVariable('showdigits','true');
  so.addVariable('autostart','true');
  so.addVariable('repeat','false');
  so.addVariable('volume','50');
  so.addVariable('screencolor', '0x000000'); // espace vidéo
  so.addVariable('backcolor', '0xAB5D2C'); // contrôles vidéo
  so.addVariable('enablejs','true');
  
  if ( autoDetectionBandePassante == 1 ) {
      so.addVariable('file', urlVideo());
      so.addVariable('bwfile', 'Images/detectBw.png');
      so.addVariable('bwstreams', '512,796');
  }
  else {
    so.addVariable('file', urlVideo());
  }
  
  //  so.addVariable('overstretch', 'none'); // pour que le 50% joue à 50% !
  
  so.write('video');
}


function getBandwidth(valeurDetectee) {
  if ( valeurDetectee < 512 ) {
    messageBandePassanteFaible();
  }
  else {
    if ( $('messageBandePassanteFaible') ) {
      $('messageBandePassanteFaible').remove();
    }
  }
}

function messageBandePassanteFaible() {
  if ( ! $('messageBandePassanteFaible') ) { // 104 220
    var s = '<div id="messageBandePassanteFaible" style="position: absolute; top: 62px; left: 220px; background-color: red; color: white; font-weight: bold;">CONNEXION INTERNET TROP FAIBLE POUR LA VIDÉO !</div>"';
    $$('body')[0].insert(s);
  }
}


function ouvreFenetre(url) {
  if ( $('mediaPlayer') ) {
    if ( videoJoue ) {
      $('mediaPlayer').sendEvent('playpause');
      videoJoue = false;
    } 
  }
  window.open(url);
}

function urlVideo() {
  if ( autoDetectionBandePassante != 1 ) {
    var bandePassanteForcee = autoDetectionBandePassante;
    if ( bandePassanteForcee < 500 ) {
      //      messageBandePassanteFaible();
    }
    return 'http://94.23.23.88/Videos/Flash/' + videoVue + '_75pct_' + bandePassanteForcee + '.flv';
  }
  else {
    return 'http://94.23.23.88/Videos/Flash/' + videoVue + '_75pct.flv';
  }
}

function chargeNouvelleVideo(laVideo) {
  $('mediaPlayer').sendEvent('stop'); // stop playing AND BUFFERING !
  
  var s = 'http://94.23.23.88/Videos/Flash/' + laVideo + '_75pct.flv'; // le préfixe 215, 512, 796 sera mis automatiquement !

  $('mediaPlayer').loadFile({file:s});
  
  // trace pour vérification si besoin !
  /*
  var obj = $('mediaPlayer').itemData( $('mediaPlayer').getLength() - 1 );
  alert(obj.file);
  */
}


/* ========== en attendant d'activer les logs ! ========== */
/*
function supprimeChronoLog() {
  return;
}

function logueInitial() {
  return;
}
*/
