					var work_rating =  {
                          offset_left: 0,
                          $el: null,
                          $votes_el: null,
                          value: 0,
                          votes: 0,
                          work_id: 0,
                          update_link: null,
                          is_enabled: false,
                          selectors: {
							activated_cls: "activated_cls"
						  },
                          init: function($el, $votes_el, update_link){
                            this.$el = $el;
                            this.$votes_el = $votes_el;
                            this.is_enabled = false;
                            this.update_link = update_link;
                            var offset = $el.offset();
                            if ($el.hasClass("stars"))
                            {
                            	var offset_parent = $el.parent().parent().offset(); 
                            	this.offset_left = offset_parent.left + Number($(".b-player-info", $el.parent().parent()).width()) + 10;
                            }
                            else
                            	this.offset_left = Number(offset.left);
                            if (!this.$el.hasClass(this.selectors.activated_cls))
                            {
	                            this.$el.mousemove(function(obj){return function(e){
	                            	if (!obj.is_enabled) return false;
	                                obj.showValue(Math.ceil((Number(e.clientX) - obj.offset_left)/15));
	                            }}(this)).mouseout(function(obj){return function(e){
	                            	if (!obj.is_enabled) return false;
	                                obj.showValue(obj.value);
	                            }}(this));
	                            this.initUpdateButton();
	                            this.$el.addClass(this.selectors.activated_cls)
                            }
                            this.$el.css({'background-image': 'url("/images/rating.png")', 'background-repeat': 'no-repeat'});
                      	  },
                      	  initUpdateButton: function()
                      	  {	
                              this.$el.one("click", function(obj){return function(e){
                            	  if (!obj.is_enabled) return false;
                                  if (obj.work_id && obj.update_link)
                                  {                                	  
                                      obj.setValue(Math.ceil((Number(e.clientX) - obj.offset_left)/15));
                                      obj.disable();
                                      $.ajax({
                                          type: "POST",
                                          dataType: "json",
                                          url: obj.update_link,
                                          data: "id=" + String(obj.work_id) + "&value=" + String(obj.value),
                                          success: function(obj){return function(result){
                                        	  if (Number(result[0]) >= 0)
                                        		  obj.setValue(result[0]);  
                                        	  if (Number(result[1]) >= 0)
                                        		  obj.setVotes(result[1]);  
                                        	  obj.enable();
                                        	  obj.initUpdateButton();
                                          }
                                      }(obj)});
                                  }
                              }}(this));                      		  
                      	  },
                      	  setWork: function(work_id, value, votes)
                      	  {
                              this.work_id = work_id;
                              this.setValue(value);
                              this.setVotes(votes);
                              this.enable();
                      	  },
                      	  enable: function()
                      	  {
                      		if (this.update_link)
                      		{
                      			this.is_enabled = true;
                      			this.$el.removeClass("disabled");
                      		}
                        	this.$el.fadeTo("slow", 1);                      		  
                      	  },
                      	  disable: function()
                      	  {
                      		this.is_enabled = false;
                  			this.$el.addClass("disabled");
                        	this.$el.fadeTo("slow", 0.5);                      		  
                      	  },
                      	  setValue: function(value)
                      	  {
                          	  if (value < 0 || value > 5)
                              	  return false;
                          	  this.value = Number(value);
                          	  this.showValue(this.value);
                      	  },
                      	  setVotes: function(votes)
                      	  {
                          	  this.votes = Number(votes);
                          	  this.$votes_el.html(this.votes);
                      	  },
                      	  showValue: function(value)
                      	  {
                              var x=0, y=0;
                              x = 75 - Math.floor(value)*15;
                              var dec = value - Math.floor(value);
                              if (dec >= 0.5)
                              {
                                x -= 15;
                                y = - 15;
                              }
                              this.$el.css({'background-position': '-' + String(x) + 'px ' + String(y) + 'px'});                          	  
                      	  }
                      	};
