  $(document).ready(function(){
    var akb = 1;
	var arb = 1;
    $("a#akb").click(function()	{$("div#karma_"+akb).hide("fast");akb = !akb + 0;$("div#karma_"+akb).show("fast");return false;  });

    $("a#arb").click(function()	{$("div#rate_"+arb).hide("fast");arb = !arb + 0;$("div#rate_"+arb).show("fast"); return false;});
    
    $('.top_friend').click(function(){
		var user_id = $(this).attr('name').substr(2);
		var type = $(this).attr('val');

		if(type==1)
			url = "/user/friend";
		else
			url = "/user/unfriend/";
		
		$.ajax({
			type: "POST",
			url: url,
			data: ({user_id: user_id}),
			dataType: "json",
			object: $(this),
			success: function(msg){
				if(msg['result'] == 1) // successs
				{
					var name = this.object.attr('name');
					if(type == 1)
					{
						
						 $('.top_friend[name=' + name + ']').text("Удалить из друзей");
						 $('.top_friend[name=' + name + ']').attr('val','0');
						
					}
					else
					{
						$('.top_friend[name=' + name + ']').text("Добавить в друзья");
						$('.top_friend[name=' + name + ']').attr('val','1');
					}
				}
			},
			error: function(msg){
				alert("Something went wrong!"); }
		});
		return false;
	});
	
  });
 