$(document).ready(function(){
  $("#quicksearch input[type=text]").val("Recherche rapide...");
  $("#quicksearch input[type=text]").focus(function() {if($(this).val() == "Recherche rapide...") $(this).val('')});
  $("#quicksearch input[type=text]").blur(function() {if($(this).val() == '') $(this).val("Recherche rapide...")});
});

$( function() {
  $('.spoiler').each( function() {
    $(this).removeClass('degrade');
    $(this).children('.title').html('<span>Spoiler</span><a class="img_link" href="#"><img src="/extension/ag_design/design/refuge/images/icons/lightbulb.png"/> Afficher/Masquer</a>');
    $(this).children('.content').wrapInner('<div class="show_hide">');

    $(this).find('.title a').click(function(){
      $(this).parent().next().children('.show_hide').slideToggle();
      return false;
    });

    $(this).find('.content .show_hide').hide();
  });

  $('.time_ago').each( function() {
    var current_date = new Date();
    var interval = Math.floor( current_date.getTime() / 1000) - $(this).attr('rel');
    var nb = 0;
    var string = '';
    if ( interval > 31536000 ) {
      nb = Math.floor( interval / 31536000 );
      string = 'il y a plus ' + ((nb == 1)?'d\'1 an':'de ') + nb + ' ans';
    }else if( interval > 2592000 ) {
      nb = Math.floor( interval / 2592000 );
      string ='il y a ' + nb + ' mois';
    }else if( interval > 604800 ) {
      nb = Math.floor( interval / 604800 );
      string ='il y a ' + nb + ' semaine' + ((nb > 1 )?'s':'');
    }else if( interval > 86400 ) {
      nb = Math.floor( interval / 86400 );
      string ='il y a ' + nb + ' jour' + ((nb > 1 )?'s':'');
    }else if( interval > 3600 ) {
      nb = Math.floor( interval / 3600 );
      string ='il y a ' + nb + ' heure' + ((nb > 1 )?'s':'');
    }else if( interval > 60 ) {
      nb = Math.floor( interval / 60 );
      string ='il y a ' + nb + ' minute' + ((nb > 1 )?'s':'');
    }else {
      string ='il y a quelques secondes';
    }
    $(this).text(string);
  });
});