(function(n){var t={init:function(i){return this.each(function(){var r,e,u,f;t.destroy.call(this);this.opt=n.extend(!0,{},n.fn.raty.defaults,i);r=n(this);e=["number","readOnly","score","scoreName"];t._callback.call(this,e);this.opt.precision&&t._adjustPrecision.call(this);this.opt.number=t._between(this.opt.number,0,this.opt.numberMax);this.opt.path=this.opt.path||"";this.opt.path&&this.opt.path.slice(this.opt.path.length-1,this.opt.path.length)!=="/"&&(this.opt.path+="/");this.stars=t._createStars.call(this);this.score=t._createScore.call(this);t._apply.call(this,this.opt.score);u=this.opt.space?4:0;f=this.opt.width||this.opt.number*this.opt.size+this.opt.number*u;this.opt.cancel&&(this.cancel=t._createCancel.call(this),f+=this.opt.size+u);this.opt.readOnly?t._lock.call(this):(r.css("cursor","pointer"),t._binds.call(this));this.opt.width!==!1&&r.css("width",f);t._target.call(this,this.opt.score);r.data({settings:this.opt,raty:!0})})},_adjustPrecision:function(){this.opt.targetType="score";this.opt.half=!0},_apply:function(n){n&&n>0&&(n=t._between(n,0,this.opt.number),this.score.val(n));t._fill.call(this,n);n&&t._roundStars.call(this,n)},_between:function(n,t,i){return Math.min(Math.max(parseFloat(n),t),i)},_binds:function(){this.cancel&&t._bindCancel.call(this);t._bindClick.call(this);t._bindOut.call(this);t._bindOver.call(this)},_bindCancel:function(){t._bindClickCancel.call(this);t._bindOutCancel.call(this);t._bindOverCancel.call(this)},_bindClick:function(){var t=this,i=n(t);t.stars.on("click.raty",function(n){t.score.val(t.opt.half||t.opt.precision?i.data("score"):this.alt);t.opt.click&&t.opt.click.call(t,parseFloat(t.score.val()),n)})},_bindClickCancel:function(){var n=this;n.cancel.on("click.raty",function(t){n.score.removeAttr("value");n.opt.click&&n.opt.click.call(n,null,t)})},_bindOut:function(){var i=this;n(this).on("mouseleave.raty",function(n){var r=parseFloat(i.score.val())||undefined;t._apply.call(i,r);t._target.call(i,r,n);i.opt.mouseout&&i.opt.mouseout.call(i,r,n)})},_bindOutCancel:function(){var t=this;t.cancel.on("mouseleave.raty",function(i){n(this).attr("src",t.opt.path+t.opt.cancelOff);t.opt.mouseout&&t.opt.mouseout.call(t,t.score.val()||null,i)})},_bindOverCancel:function(){var i=this;i.cancel.on("mouseover.raty",function(r){n(this).attr("src",i.opt.path+i.opt.cancelOn);i.stars.attr("src",i.opt.path+i.opt.starOff);t._target.call(i,null,r);i.opt.mouseover&&i.opt.mouseover.call(i,null)})},_bindOver:function(){var i=this,r=n(i),u=i.opt.half?"mousemove.raty":"mouseover.raty";i.stars.on(u,function(u){var f=parseInt(this.alt,10),e,o;i.opt.half?(e=parseFloat((u.pageX-n(this).offset().left)/i.opt.size),o=e>.5?1:.5,f=f-1+o,t._fill.call(i,f),i.opt.precision&&(f=f-o+e),t._roundStars.call(i,f),r.data("score",f)):t._fill.call(i,f);t._target.call(i,f,u);i.opt.mouseover&&i.opt.mouseover.call(i,f,u)})},_callback:function(n){for(i in n)typeof this.opt[n[i]]=="function"&&(this.opt[n[i]]=this.opt[n[i]].call(this))},_createCancel:function(){var i=n(this),r=this.opt.path+this.opt.cancelOff,t=n("",{src:r,alt:"x",title:this.opt.cancelHint,"class":"raty-cancel"});return this.opt.cancelPlace=="left"?i.prepend(" ").prepend(t):i.append(" ").append(t),t},_createScore:function(){return n("",{type:"hidden",name:this.opt.scoreName}).appendTo(this)},_createStars:function(){for(var u=n(this),f,r,i=1;i<=this.opt.number;i++)f=t._getHint.call(this,i),r=this.opt.score&&this.opt.score>=i?"starOn":"starOff",r=this.opt.path+this.opt[r],n("",{src:r,alt:i,title:f}).appendTo(this),this.opt.space&&u.append(if){var r=t.opt.iconRange[f],s=r.on||t.opt.starOn,h=r.off||t.opt.starOff,u=o?s:h;i<=r.range&&e.attr("src",t.opt.path+u);i==r.range&&f++}else u=o?"starOn":"starOff",e.attr("src",this.opt.path+this.opt[u])},_getHint:function(n){var t=this.opt.hints[n-1];return t===""?"":t||n},_lock:function(){var i=parseInt(this.score.val(),10),r=i?t._getHint.call(this,i):this.opt.noRatedMsg;n(this).data("readonly",!0).css("cursor","").attr("title",r);this.score.attr("readonly","readonly");this.stars.attr("title",r);this.cancel&&this.cancel.hide()},_roundStars:function(n){var i=(n-Math.floor(n)).toFixed(2),t;i>this.opt.round.down&&(t="starOn",this.opt.halfShow&&i1?t:t[0]},readOnly:function(i){return this.each(function(){var r=n(this);r.data("readonly")!==i&&(i?(r.off(".raty").children("img").off(".raty"),t._lock.call(this)):(t._binds.call(this),t._unlock.call(this)),r.data("readonly",i))})},reload:function(){return t.set.call(this,{})},score:function(){return arguments.length?t.setScore.apply(this,arguments):t.getScore.call(this)},set:function(t){return this.each(function(){var i=n(this),r=i.data("settings"),u=n.extend({},r,t);i.raty(u)})},setScore:function(i){return n(this).each(function(){n(this).data("readonly")!==!0&&(t._apply.call(this,i),t._target.call(this,i))})}};n.fn.raty=function(i){if(t[i])return t[i].apply(this,Array.prototype.slice.call(arguments,1));if(typeof i!="object"&&i)n.error("Method "+i+" does not exist!");else return t.init.apply(this,arguments)};n.fn.raty.defaults={cancel:!1,cancelHint:"Cancel this rating!",cancelOff:"cancel-off.png",cancelOn:"cancel-on.png",cancelPlace:"left",click:undefined,half:!1,halfShow:!0,hints:["bad","poor","regular","good","gorgeous"],iconRange:undefined,mouseout:undefined,mouseover:undefined,noRatedMsg:"Not rated yet!",number:5,numberMax:20,path:"",precision:!1,readOnly:!1,round:{down:.25,full:.6,up:.76},score:undefined,scoreName:"score",single:!1,size:16,space:!0,starHalf:"star-half.png",starOff:"star-off.png",starOn:"star-on.png",target:undefined,targetFormat:"{score}",targetKeep:!1,targetText:"",targetType:"hint",width:undefined}})(jQuery)