jQuery(document).ready(function()
{
  // Comment lists hovers
  jQuery('ul.comments > li').live('mouseenter', function(e)
  {
    // Show the action list
    var actionsDiv = jQuery(this).children('div.actions');
    actionsDiv.show();
  });

  jQuery('ul.comments > li').live('mouseleave', function(e)
  {
    // Do not hide the actions list if it is opened
    var actionsDiv = jQuery(this).children('div.actions');
    if(!jQuery('ul', actionsDiv).is(':visible'))
    {
      actionsDiv.hide();
    }
  });

  jQuery('ul.comment-form a.ajax-submit').live('click', function(e)
  {
    e.preventDefault();
    var form = jQuery(this).parents('form');

    form.ajaxSubmit({
      success: function(html, statusText) {
        displayNotice('Votre commentaire a été ajouté.');

        var ul = form.prev().prev().find('ul.comments');
        ul.html(ul.html()+html);
        form.find('textarea').val('');

        // hide markups of 'no comment yet' messages
        form.prev().prev().children('p').hide();
      },
      error:  function(e) {displayError('Une erreur s\'est produite. Votre commentaire n\'a pas été ajouté.');}
    })
  });
});



