function rating(sOptions){
	this.properties = {
		site_url: '',
		ratingUrl: 'rating/ajax_rating_vote',
		reloadFormUrl: 'rating/ajax_rating_form',
		ratingFullUrl: '',
		error_object:  new Errors,
		reloadFullUrl: ''
	}

	var _self = this;

	this.errors = {
		success: 'Спасибо за оценку!',
		already_mark: 'Вы уже оценивали эту работу'
	}

	this.Init = function(options){
		_self.properties = $.extend(_self.properties, options);
		_self.properties.ratingFullUrl = _self.properties.site_url + _self.properties.ratingUrl;
		_self.properties.reloadFullUrl = _self.properties.site_url + _self.properties.reloadFormUrl;
		_self.properties.error_object.extend_errors(_self.errors);
	}

	this.vote = function(object_id, rating_gid){
		var vote = $(":radio[name=vote]:checked:first").val();
		var url = _self.properties.ratingFullUrl + '/' + rating_gid + '/' + object_id + '/' + vote;
		$.ajax({
			url: url, 
			cache: false,
			success: function(data){
				_self.reload_vote(object_id, rating_gid);
				if(data == 'success')
					_self.properties.error_object.show_error_block(_self.errors[data], 'success');
				else
					_self.properties.error_object.show_error_block(_self.errors[data], 'error');
			}
		});
	}
	
	this.reload_vote = function(object_id, rating_gid){
		$.ajax({
			url: _self.properties.reloadFullUrl + '/' + rating_gid + '/' + object_id, 
			cache: false,
			success: function(data){
				$("#rating_vote_form").replaceWith(data);
			}
		});
	}
	_self.Init(sOptions);

};

