$(function(){
  duration=600;
  delay=200;

  // menus (horizontaux) : OK
  $("#menu0 dl").mouseover(function(){
    $(this).children('dd').stop(true, true).fadeIn(600);
  });
  $("#menu0 dl").mouseout(function(){
    $(this).children('dd').stop(true, true).delay(200).fadeOut(600);
  });
  $("#menu0 dt").not(':has(a)').toggle(
    function(){
      $(this).parent().children('dd').stop(true, true).delay(200).fadeOut(600);
    },
    function(){
      $(this).parent().children('dd').stop(true, true).fadeIn(600);
    }
  );
  // menus (verticaux) : sur click uniquement
  $("#menu dt").toggle(
    function(){
      $(this).parent().children('dd').stop(true, true).slideUp();
    },
    function(){
      $(this).parent().children('dd').stop(true, true).slideDown();
    }
  );
});

function ini_menu(on_off)
{
  if (on_off === 0) { 
    $("#menu dl").children('dd').slideUp();
  }
  else {
    $("#menu dl").children('dd').slideDown();
  }
}

// Gestion blocs biblio
function switch_head() {
 if ($("#head").css('display') == "block") {
   $("#head").css( { 'display' : "none" } );
   $('#head0').html("Afficher plus d'informations");
 }
 else {
   $("#head").css( { 'display' : "block" } );
   $('#head0').html("Cacher les informations");
 }
}

// afficher/cacher un bloc 
function onoff(obj, classe) {
  var cacher = $("."+classe).first().css('display') != 'none';
  $("."+classe).each(function(){
    $(this).css( { 'display' : (cacher == true ? "none" : "block") } );
  });
  // Mise a jour automatique du label, si possible
  var label = $(obj).html();
  if (cacher == true)
    label = label.replace("Cacher les", "Afficher les");  
  else
    label = label.replace("Afficher les", "Cacher les");  
  $(obj).html(label);
}

function switch_debug() {
  var normal = $("#dbg_0").html() == "Mode normal";

  $('#dbg_0').css( {'background' : (normal ? "#ade" : "#ccc") } );
  $('#dbg_0').html( normal ? "Infos manquantes" : "Mode normal" );
  $(".tbc").css( {'background' : (normal ? "#eee" : "#afa") } );
}
function init_debug() {
  // double switch pour re-initialisation couleurs
  switch_debug();
  switch_debug();
}
 
// autres fonctions anciennes - voir si reécriture/améliorations possibles...

function mail_cycles()
{
   window.open("../../commun/mail_cycles.php", "Avmail", "locationbar=no,toolbar=no,name=\"ahaha\",width=520,height=350,resizable=yes,scrollbars=yes,alwaysraised=yes,dependent=no,titlebar=no,menubar=no,hotkeys=no");
}

function mail()
{
   window.open("../../commun/mail.php", "Avmail", "locationbar=no,toolbar=no,name=\"ahaha\",width=520,height=360,resizable=yes,scrollbars=yes,alwaysraised=yes,dependent=no,titlebar=no,menubar=no,hotkeys=no");
}

function mail_prix()
{
   window.open("../commun/mail_prix.php", "Avmail", "locationbar=no,toolbar=no,name=\"ahaha\",width=520,height=350,resizable=yes,scrollbars=yes,alwaysraised=yes,dependent=no,titlebar=no,menubar=no,hotkeys=no");
}

function mail_anthos()
{
   window.open("../../commun/mail_recueils.php", "Avmail", "locationbar=no,toolbar=no,name=\"ahaha\",width=520,height=350,resizable=yes,scrollbars=yes,alwaysraised=yes,dependent=no,titlebar=no,menubar=no,hotkeys=no");
}

function mail_collec()
{
   window.open("../../commun/mail_collec.php", "Avmail", "locationbar=no,toolbar=no,name=\"ahaha\",width=520,height=350,resizable=yes,scrollbars=yes,alwaysraised=yes,dependent=no,titlebar=no,menubar=no,hotkeys=no");
}

function dcod (_code) {
 var key = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1029384756><#].";
 var wTG;var mcH=key.length/2;var _txt="";var dv;
 for (var x=0; x<_code.length; x++) {
  wTG = key.indexOf(_code.charAt(x));
  if (wTG>mcH) {dv=wTG-mcH;_txt+=key.charAt(33-dv);}
  else {
   if (key.indexOf(_code.charAt(x))<0) {
    _txt+=_code.charAt(x);} 
   else {dv=mcH-wTG; _txt+=key.charAt(33+dv);}
  }
 }
 return (_txt);
}

function aff_mail(dest, msg, sujet, fin) {
 var cod="";
 if (dest == "cg") {
  cod="b] zp89=\"u]yvns:0yvv8o@<79yAt8n;6zpyony]t@<79yAt8n\"C0yvv8o@<79yAt8n;6zpyony]t@<79yAt8nb/]C";}
 else if (dest == "gc") {
  cod="b] zp89=\"u]yvns:6zpyony]t@<79yAt8n;0yvv8o@<79yAt8n\"C6zpyony]t@<79yAt8n;0yvv8o@<79yAt8nb/]C";}
 else if (dest == "c") {
  cod="b] zp89=\"u]yvns:6zpyony]t@<79yAt8n\"C6zpyony]t@<79yAt8nb/]C";}
 else if (dest == "g") {
  cod="b] zp89=\"u]yvns:0yvv8o@<79yAt8n\"C0yvv8o@<79yAt8nb/]C";}
 var f=cod.length-4;
 var d=7+(f/2);
 if (cod != "") {
  adr = dcod(cod);
  if (msg != "") { adr = adr.substr(0,d+2) + msg + adr.substr(f);}
  if (sujet != "") { adr = adr.substr(0,d) + "?subject=" + sujet + adr.substr(d);}
  if (fin == 1) { adr = adr.substr(0,2) + " onclick=\"mclose()\" " + adr.substr(2);}
  document.write(adr);
 }
}

function mclose()
{
   setTimeout("javascript:self.close()",3000);
}

function certif(type, path, lien)
{
 path+="/";
 document.write ("<p>");
 if (type == "xhtml")
 {
    if (lien == 1)
    {
       document.write (" <a href=\"http://validator.w3.org/check?uri=referer\"><img src=\""+path+"images/valid-xhtml10\" alt=\"Valid XHTML 1.0!\" border=\"0\" height=\"31\" width=\"88\" /></a>");
    }
    else
    {
       document.write (" <img src=\""+path+"images/valid-xhtml10\" alt=\"Valid XHTML 1.0!\" border=\"0\" height=\"31\" width=\"88\" />");
    }
 }
 document.write ("</p>");
}

function aff_datemod()
{
  document.write("Dernière mise &agrave; jour : " + document.lastModified);
}

var newurl="";
var newwin=0;
function go_url()
{
  if (newurl != "") {
    if (newwin == 0) { document.location.replace(newurl); }
    else             { window.open(newurl); }
    newurl="";
  }
  else
  {
     alert("Remplissez la zone de recherche...");
  }
  return false;
}

function repurl(path, typ)
{
  value=document.getElementById("bdfi_cherche").value;
  if (value != "")
  {
    if (typ == "antinea")
    {
      newurl="http://search.antinea.org/findit.php3?b=imagine&q="+value;
      newwin=1;
    }
    else if ((typ == "auteur") || (typ == "serie") || (typ == "recueil") || (typ == "collection"))
    {
      newurl=path+typ+"s/recherche.php?str="+value;
      newwin=0;
    }
    else if (typ == "topics")
    {
      newurl=path+"search.php?action=search&keywords="+value+"&search_in=titles&show_as=topics&search=Submit";
    }
    else if (typ == "posts")
    {
      newurl=path+"search.php?action=search&keywords="+value+"&show_as=posts&search=Poster";
    }
    else if (typ == "wiki")
    {
      newurl=path+"doku.php?do=search&id="+value;
    }
    else if (typ == "base")
    {
      newurl="http://search.antinea.org/findit.php3?b=imagine&q="+value;
      newwin=1;
    }
    document.getElementById("bdfi_cherche").value = "";
  }
}

