// Marque page et favoris
function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}
// Alternative valide W3C _blank
function lien(monLien) {
window.open(monLien, '_blank');
return false;
}
// Plan
function depli(idBloc)
{
  obj = document.getElementById(idBloc);
  obj.style.display = obj.style.display==''?'none':'';
  return false;
}
//******************************************************************************
var xhr_object = null;
var lastobj = null;

function getNextCallback()
{
  if ((xhr_object.readyState == 4))
  {
    document.body.style.cursor = 'default';
    texte = xhr_object.responseText.split('#');

    var idVideo = texte[1];
    if (texte[3] >= 0) {

      obj = document.getElementById('tnote');
      if (obj)
        obj.innerHTML = texte[3] + ' ' + texte[4];

      if (texte[2]==1) {
        defautNote[idVideo] = Math.round(texte[3]);
        afficheNote(idVideo, -1);
      }
      else if (texte[2]==2) {
        defautNotePh[idVideo] = Math.round(texte[3]);
        afficheNotePhoto(idVideo, -1);
      }
    }

    if (texte[0] != '')
      alert(texte[0]);
  }
}

//******************************************************************************
function appelAjax(obj, url)
{
  if (xhr_object == null)
    if(window.XMLHttpRequest)
      xhr_object = new XMLHttpRequest();
    else if(window.ActiveXObject)
      xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
    else
      return true;

  xhr_object.open("GET", url, true);
  xhr_object.onreadystatechange = getNextCallback;
  xhr_object.send(null);

  document.body.style.cursor = 'wait';
  return false;
}

//******************************************************************************
function NoteVideo(idVideo, note)
{
  appelAjax(null, 'ajax_note.php?idVideo=' + idVideo + '&note=' + note);
  return true;
}

//******************************************************************************
function NotePhoto(idPhoto, note)
{
  appelAjax(null, 'ajax_note_photo.php?idPhoto=' + idPhoto + '&note=' + note);
  return true;
}

//******************************************************************************
function afficheNote(idVideo, note)
{
  if (note < 0) { active = 'on'; note = defautNote[idVideo]; } else active = 'over';
  for (i = 1; i <= 5; i++)
    document.getElementById('note_etoile'+i+'_'+idVideo).src='img/star-' + (note>=i?active:'off') + '.png';
}

//******************************************************************************
function afficheNotePhoto(idPhoto, note)
{
  if (note < 0) { active = 'on'; note = defautNotePh[idPhoto]; } else active = 'over';
  for (i = 1; i <= 5; i++)
    document.getElementById('note_etoile'+i+'_ph'+idPhoto).src='img/star-' + (note>=i?active:'off') + '.png';
}

//******************************************************************************
function changeOnglet(onglet, va){
  document.getElementById('tab_1_contents').className = 'tab_contents'+(onglet==1?' tab_contents_active':'');
  document.getElementById('tab_2_contents').className = 'tab_contents'+(onglet==2?' tab_contents_active':'');

  document.getElementById('onglet1').className = (onglet==1?'active':'');
  document.getElementById('onglet2').className = (onglet==2?'active':'');

  if (va) self.location.hash='#tabOnglet';

  return false;
}
//*******************************************************************************
// Load this script when page loads
$(document).ready(function(){

 // Set up a listener so that when anything with a class of 'tab' 
 // is clicked, this function is run.
 $('.tab').click(function () {

  // Remove the 'active' class from the active tab.
  $('#tabs_container > .tabs > li.active')
	  .removeClass('active');
	  
  // Add the 'active' class to the clicked tab.
  $(this).parent().addClass('active');

  // Remove the 'tab_contents_active' class from the visible tab contents.
  $('#tabs_container > .tab_contents_container > div.tab_contents_active')
	  .removeClass('tab_contents_active');

  // Add the 'tab_contents_active' class to the associated tab contents.
  $(this.rel).addClass('tab_contents_active');

 });
});
