
// Mettre à jour un élément du dom aprés un certain temps
function refreshElement(timeout, element, url) {
   jQuery(element).fadeTo(timeout, 1, function(){
       jQuery.ajax({
           type: "GET",
           url: url,
           dataType: "html",
           success: function(data){
               var div = "<div>"+data+"</div>";
               jQuery(div).prependTo(element).hide().fadeIn(1000);
           }
       }); 
   });
}

// Afficher le laoding
function showLoading(element) {
    var loading= jQuery(element).children(loading);
    jQuery(element).html('<div class="loading">' + jQuery(loading).html() + '</div>');
    jQuery(loading).removeClass('hiddendiv');
}

jQuery(document).ready(function(){

    // Selectionner tout dans le formulaire de recherche
    jQuery('#search_input').live('click', function(){
        var value = jQuery(this).attr('value');
        if (value == "Rechercher sur bloginy") {
            jQuery(this).attr('value', '');
        }
    });
    
    // Supprimer un tag
    jQuery('.deleteTag').live('click', function(){
        jQuery(this).closest('.newtag').remove();
        return false;
    });
    
    // Gestion des tabulations
    jQuery('.content-tabs a').live('click', function(){
    
        if (!$(this).hasClass('activeTab')) {
            if ($(this).hasClass('ajax') && !$(this).hasClass('loaded')) {
                var url = $(this).attr('customhref');
                var div = $(this).attr('href');
                $(this).addClass('loaded');
                $.ajax({
                    type: "GET",
                    url: url,
                    dataType: "html",
                    success: function(data){
                        $(div).html(data);
                    }
                });
            }
            var contentblocks = $(this).closest('.content-tabs').siblings('.content-blocks-tabs');
            $(this).closest('.content-tabs').find('a').removeClass('activeTab');
            $(this).addClass('activeTab');
            $(contentblocks).find('div').removeClass('activeBlock');
            $(contentblocks).find($(this).attr('href')).addClass('activeBlock');
        }
        
        return false;
    });
    
    // Gestion des liens en Ajax
    jQuery('.ajaxLink').live('click', function() {
      var confirmation = true;
      if ($(this).attr('confirmation'))
      {
        confirmation = confirm($(this).attr('confirmation'));
      }
      
      if (confirmation)
      {
        var url = $(this).attr('href');
        var update = $(this).attr('update');
        $.ajax({
          type: "GET",
          url: url,
          dataType: "html",
          success: function(data){
              $(update).html(data);
          }
        });
      }
      
      return false;
    });
    
});
