
$(document).ready(function(){
  
  $(".fancy").fancybox({
    'titlePosition'  : 'over'
  });
  
  $('#nav_principale .menu_mainsite li').corner('5px');
  $('#nav_principale .menu_televerbier li').corner('5px');

  $(".iframeGoogleMap").fancybox({
    'width'        : 600,
    'height'      : 380,
    'autoScale'       : false,
    'transitionIn'    : 'none',
    'transitionOut'    : 'none',
    'type'        : 'iframe'
  });    
  
  $(".fancyvideohome").fancybox({
    'width'        : 600,
    'height'      : 380,
    'autoScale'       : false,
    'transitionIn'    : 'none',
    'transitionOut'    : 'none',
    'type'        : 'iframe'
  });
  
  /*$(".iframeFavoris").fancybox({
    'width'        : 300,
    'height'      : 200,
    'autoScale'       : false,
    'transitionIn'    : 'none',
    'transitionOut'    : 'none',
    'type'        : 'iframe',
    'titlePosition'   : 'over'
  });    */
    
});


function ajouterFavoris(url){
  $.post("/scripts/php/favoris/favoris-add.php", { page: url, titre: document.title } );
  $("#accrocheFavoris").load("/scripts/php/favoris/favoris-get.php");
}

function deleteFavori(favtime){
  $.post("/scripts/php/favoris/favoris-delete.php", { t: favtime } );
  $("#accrocheFavoris").load("/scripts/php/favoris/favoris-get.php");
}

function loadFavorisBox(){
  $("#accrocheFavoris").load("/scripts/php/favoris/favoris-get.php");
}


/* common js functions */

function email_valide(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      return false;
   }
   return true;
}




function getXhr(){
  var xhr = null;

  if(window.XMLHttpRequest) // Firefox et autres
     xhr = new XMLHttpRequest();
  else if(window.ActiveXObject){ // Internet Explorer
    try {
      xhr = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  else { // XMLHttpRequest non supporté par le navigateur
     alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
     xhr = false;
  }

  return xhr;
}

function getCategories(idCat) {
  var xhr = getXhr();

  // On défini ce qu'on va faire quand on aura la réponse
  xhr.onreadystatechange = function(){
    // On ne fait quelque chose que si on a tout reçu et que le serveur est ok
    if(xhr.readyState == 4 && xhr.status == 200){
      document.getElementById('categoryList').innerHTML = xhr.responseText;
    }
  }

  xhr.open("POST","/scripts/php/ajax/galerie_photos.php",true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xhr.send("idCat=" + idCat);
}


function emailLink(){
  var a = emailLink.arguments;
  var ret = "";
  if(a.length >= 3){
    for(i=2; i<a.length; i++){
      ret += a[i]+'.';
    }
    ret = ret.substr(0, ret.length - 1)+'@'+a[1];
  }
  document.write('<a href="mailto:'+ret+'" class="contact_lien">'+a[0]+'</a>');
}
