(function( $ ){
  
  $.fn.UsersRating = function(options){ 
     var page       = options.page;
     var rating     = options.rating ? true : false;
     $(this).click(function(){
        var pluse = $(this).attr('class')=="up" ? true : false;
        var id    = $(this).parent().attr('id') ? $(this).parent().attr('id') : 0;
        var type  = $(this).parent().attr('type') ? $(this).parent().attr('type') : null;
        var users = $(this).parent().attr('users') ? $(this).parent().attr('users') : 0;
        var THIS = this;
        $.post("/ajax/rating_users.html",{'page': page,'pluse': pluse,'id': id,'type': type,'users': users },function(data){
          var res = data.result;
          var error = data.error;
          if(res==true && rating==false){
              var count = ($(THIS).parent().find('.rate').html()*1);
              if(pluse){
                $(THIS).parent().find('.rate').html(count+1);
              }else{
                $(THIS).parent().find('.rate').html(count-1);
              }
          }else{
            MessageWarning(error);
          }
        },'json');
        
        return false;
     });
  };
  
  
})( jQuery );


