!function(t){t.rating=function(s,i){this.options=t.extend({fx:"float",image:"https://midi-mp3.org/style/img/stars-16.png",stars:5,minimal:0,titles:["голос","голоса","голосов"],readOnly:!1,url:"/rating.php",type:"post",loader:"/style/img/ajax-loader.gif",click:function(){},callback:function(){}},i||{}),this.el=t(s),this.left=0,this.width=0,this.height=0,this._data={};var a=this;this.el.find(":hidden").each(function(){var s=t(this);a._data[s.attr("name")]=s.val()}),this._data.val=parseFloat(this._data.val)||0,this._data.votes=parseFloat(this._data.votes)||"",this._data.val>this.options.stars&&(this._data.val=this.options.stars),this._data.val<0&&(this._data.val=0),this.old=this._data.val,this.vote_wrap=t('<span class="vote-wrap"></span>'),this.vote_block=t('<span class="vote-block"></span>'),this.vote_hover=t('<span class="vote-hover"></span>'),this.vote_stars=t('<span class="vote-stars"></span>'),this.vote_active=t('<span class="vote-active"></span>'),this.vote_result=t('<span class="vote-result"></span>'),this.vote_success=t('<span class="vote-success"></span>'),this.loader=t('<img src="'+this.options.loader+'" alt="load...">'),this.el.html(this.loader);var o=new Image;o.src=this.options.image,o.onload=function(){a.width=this.width,a.height=this.height/3,a.init()}};var s=t.rating;s.fn=s.prototype={rating:"2.0"},s.fn.extend=s.extend=t.extend,s.fn.extend({init:function(){if(this.render(),!this.options.readOnly){var s=this,i=0,a=0;this.vote_hover.bind("mousemove mouseover",function(o){if(!s.options.readOnly){var e,n=t(this);i=o.clientX>0?o.clientX:o.pageX,a=i-n.offset().left-2;var h=s.width*s.options.stars,l=s.options.minimal*s.width;a>h&&(a=h),a<l&&(a=l),Math.round(a/s.width*10)/10,"half"==s.options.fx?a=Math.ceil(a/s.width*2)*s.width/2:"float"!=s.options.fx&&(a=Math.ceil(a/s.width)*s.width),e=Math.round(a/s.width*10)/10,s.vote_active.css({width:a,"background-position":"left center"}),s.vote_success.html("Оценка: "+e)}}).bind("mouseout",function(){s.options.readOnly||(s.reset(),s.vote_success.empty())}).bind("click.rating",function(){if(!s.options.readOnly){var t=Math.round(a/s.width*10)/10;t>s.options.stars&&(t=s.options.stars),t<0&&(t=0),s.old=s._data.val,s._data.val=(s._data.val*s._data.votes+t)/(s._data.votes+1),s._data.val=Math.round(100*s._data.val)/100,s._data.score=t,s.vote_success.html("Ваша оценка: "+t),""!=s.options.url&&s.send(),s.options.readOnly=!0,s.options.click.apply(this,[t])}})}},set:function(){this.vote_active.css({width:this._data.val*this.width,"background-position":"left bottom"})},reset:function(){this.vote_active.css({width:this.old*this.width,"background-position":"left bottom"})},setvoters:function(){this.vote_result.html(this.declOfNum(this._data.votes))},render:function(){this.el.html(this.vote_wrap.append(this.vote_hover.css({padding:"0 4px",height:this.height,width:this.width*this.options.stars}),this.vote_result.text(this.declOfNum(this._data.votes)),this.vote_success)),this.vote_block.append(this.vote_stars.css({height:this.height,width:this.width*this.options.stars,background:"url('"+this.options.image+"') left top"}),this.vote_active.css({height:this.height,width:this._data.val*this.width,background:"url('"+this.options.image+"') left bottom"})).appendTo(this.vote_hover)},send:function(s){var i=this;this.vote_result.html(this.loader),this._data.votes++,t.ajax({url:i.options.url,type:i.options.type,data:this._data,dataType:"json",success:function(t){"OK"==t.status?i.set():(i._data.votes--,i.reset()),i.setvoters(),t.msg&&i.vote_success.html(t.msg),"function"==typeof i.options.callback&&i.options.callback.apply(i,[t])}})},declOfNum:function(t){return t<=0?"":(t=Math.abs(Math.floor(t)),cases=[2,0,1,1,1,2],t+" "+this.options.titles[t%100>4&&t%100<20?2:cases[t%10<5?t%10:5]])}}),t.fn.rating=function(i){if("string"==typeof i){var a=t(this).data("rating"),o=Array.prototype.slice.call(arguments,1);return a[i].apply(a,o)}return this.each(function(){var a=t(this).data("rating");a?(i&&t.extend(a.options,i),a.init()):t(this).data("rating",new s(this,i))})}}(jQuery),$(function(){$("#rating").rating({})});