function Frating(id,objectId,objectClass,uri,params){
	this.id = id;
	this.objectId = objectId;
	this.objectClass = objectClass;
	this.uri = uri
	this.min = params["min"] || -5;
	this.max = params["max"] || 5;
	this.current = params["current"] || 0;
	this.disabled = params["disabled"] || false;
	this.allowRevote = params["allowRevote"] || false;
	this.type = params["type"] || 'user';
	var elem = this;
	var links = $('#ul_'+this.id+" > li > a");
	for (var i=0;i<links.length;i++){
		$(links[i]).click(function(){
			return elem.rate(this);
		});
	}
	
	this.update();
}

Frating.prototype.rate = function(ob){
	if(this.disabled){
		this.update();
	} else {
		var object = this;
		$.get(
			this.uri,
			{'id':this.objectId,'class':this.objectClass,'value':$(ob).text()},
			function(data){
				data = parseInt(data);
				if(data && data >= object.min && data <= object.max && !object.disabled ){
					object.current = data;
				}
				object.update();
				if(!object.allowRevote){
					object.disable();
				}
			}
		);
	}
	return false;
}

Frating.prototype.update = function(){
	var koef = 0;
	if (this.current < 0){
		koef = this.current + 6;
	}
	if (this.current > 0){
		koef = this.current + 5;
	}
	$("#"+this.id).parent().find('.current-rating').width(koef*15);
}

Frating.prototype.disable = function(){
	this.disabled = true;
	$("#ul_"+this.id).addClass('frating-disabled');
}