jQuery.fn.carma = function(options) {
	var self = this;
	
	// Определяем параметры по умолчанию
	var settings = jQuery.extend({}, options);
	
	$(this).click(function() {
		$.post(settings.url, {}, function(response) {
			$('#' + settings.responseDiv).html(response.carma);
			$(self).hide();
			Cufon.replace('h2');
			Cufon.replace("h1");
		}, 'json');
	});
};


function carma_callback(data, textStatus)
{
	if (textStatus == 'success')
	{
		if (typeof(data.carma) != 'undefined')
			$('#user_carma').html('' + data.carma);
		
		if (data.message)
			alert(data.message);
	}
	else
		alert(textStatus);
}

function carma_rate(user_id, type, rating)
{
	user_id = parseInt(user_id);
	rating = parseInt(rating) > 0 ? 1 : 0;
	
	if (user_id)
		$.getJSON('/' + type + '/rate/' + user_id + '?r=' + rating, '', carma_callback);
}
