
$(document).ready(function(){ecouteComment();ecoutePlusComment();ecouteSupprComment();});function ecouteComment(){$('#submit_commentaire').live('click',function(e){var form=$(this).parent('.form_commentaire');e.preventDefault();var dataPost=new Object();form.find(':input').each(function(){var name=$(this).attr('name');var value=$(this).val();dataPost[name]=value;});form.slideUp('slow',function(){$('.no-comment').fadeOut('slow');$.post('ajax/envoi-commentaire.html',dataPost,function(response){var nv_form=$(response);nv_form.hide();form.replaceWith(nv_form);nv_form.slideDown('slow');updateBulle(dataPost['id']);});});});}
function updateBulle(id){if($('#bulle-'+id).length>0){var dataPost=new Object();dataPost['id']=id;$.post('ajax/update-bulle-commentaire.html',dataPost,function(response){$('#bulle-'+id+' > span').text(response);});}}
function ecoutePlusComment(){$(".more-comment").live('click',function(e){e.preventDefault();var dataPost=new Object();var type_comment='';if($(this).parent().prevAll('h4').hasClass('media')){type_comment='media';}else{type_comment='profil';}
var last_div=$(this).parent().prev('div');var last_id=last_div.attr('id').split('_');var tempo_id=$(this).parent().prevAll('h4').attr('id').split('_');dataPost['id']=tempo_id[1];dataPost['type_comment']=type_comment;dataPost['last_id']=last_id[2];$(this).fadeOut('slow',function(){$(this).parent('p').remove();$.post('ajax/plus-commentaire.html',dataPost,function(response){var nv_comment=$(response);nv_comment.css('display','none');last_div.after(nv_comment);nv_comment.slideDown('slow');});});});}
function ecouteSupprComment(){$('.commentaire .suppr').live('click',function(e){e.preventDefault();var dataPost=new Object();var type_comment='';var comment=$(this).parents('.commentaire');var id=comment.attr('id').split('_');if(comment.prevAll('h4').hasClass('media')){type_comment='media';}else{type_comment='profil';}
dataPost['type_comment']=type_comment;dataPost['id']=id[2];var id_media=comment.prevAll('h4').attr('id').split('_');$.post('ajax/suppr-commentaire.html',dataPost,function(response){if(response){comment.slideUp('slow');updateBulle(id_media[1]);}});});}
