!function(l){"use strict";var c={init:function(t){return this.each(function(){this.self=l(this),c.destroy.call(this.self),this.opt=l.extend(!0,{},l.fn.um_raty.defaults,t),c._adjustCallback.call(this),c._adjustNumber.call(this),"img"!==this.opt.starType&&c._adjustStarType.call(this),c._adjustPath.call(this),c._createStars.call(this),this.opt.cancel&&c._createCancel.call(this),this.opt.precision&&c._adjustPrecision.call(this),c._createScore.call(this),c._apply.call(this,this.opt.score),c._target.call(this,this.opt.score),this.opt.readOnly?c._lock.call(this):(this.style.cursor="pointer",c._binds.call(this)),this.self.data("options",this.opt)})},_adjustCallback:function(){for(var t=["number","readOnly","score","scoreName","target"],a=0;a<t.length;a++)"function"==typeof this.opt[t[a]]&&(this.opt[t[a]]=this.opt[t[a]].call(this))},_adjustNumber:function(){this.opt.number=c._between(this.opt.number,1,this.opt.numberMax)},_adjustPath:function(){this.opt.path=this.opt.path||"",this.opt.path&&"/"!==this.opt.path.charAt(this.opt.path.length-1)&&(this.opt.path+="/")},_adjustPrecision:function(){this.opt.half=!0,this.opt.targetType="score"},_adjustStarType:function(){this.opt.path="";for(var t=["cancelOff","cancelOn","starHalf","starOff","starOn"],a=0;a<t.length;a++)this.opt[t[a]]=this.opt[t[a]].replace(".","-")},_apply:function(t){c._fill.call(this,t),t&&(0<t&&this.score.val(c._between(t,0,this.opt.number)),c._roundStars.call(this,t))},_between:function(t,a,e){return Math.min(Math.max(parseFloat(t),a),e)},_binds:function(){this.cancel&&(c._bindOverCancel.call(this),c._bindClickCancel.call(this),c._bindOutCancel.call(this)),c._bindOver.call(this),c._bindClick.call(this),c._bindOut.call(this)},_bindClick:function(){var e=this;e.stars.on("click.um_raty",function(t){var a=l(this);e.score.val(e.opt.half||e.opt.precision?e.self.data("score"):this.alt||a.data("alt")),e.opt.click&&e.opt.click.call(e,+e.score.val(),t)})},_bindClickCancel:function(){var a=this;a.cancel.on("click.um_raty",function(t){a.score.removeAttr("value"),a.opt.click&&a.opt.click.call(a,null,t)})},_bindOut:function(){var e=this;e.self.on("mouseleave.um_raty",function(t){var a=+e.score.val()||void 0;c._apply.call(e,a),c._target.call(e,a,t),e.opt.mouseout&&e.opt.mouseout.call(e,a,t)})},_bindOutCancel:function(){var s=this;s.cancel.on("mouseleave.um_raty",function(t){var a=s.opt.cancelOff;if("img"!==s.opt.starType&&(a=s.opt.cancelClass+" "+a),c._setIcon.call(s,this,a),s.opt.mouseout){var e=+s.score.val()||void 0;s.opt.mouseout.call(s,e,t)}})},_bindOver:function(){var e=this,t=e.opt.half?"mousemove.um_raty":"mouseover.um_raty";e.stars.on(t,function(t){var a=c._getScoreByPosition.call(e,t,this);c._fill.call(e,a),e.opt.half&&(c._roundStars.call(e,a),e.self.data("score",a)),c._target.call(e,a,t),e.opt.mouseover&&e.opt.mouseover.call(e,a,t)})},_bindOverCancel:function(){var s=this;s.cancel.on("mouseover.um_raty",function(t){var a=s.opt.path+s.opt.starOff,e=s.opt.cancelOn;"img"===s.opt.starType?s.stars.attr("src",a):(e=s.opt.cancelClass+" "+e,s.stars.attr("class",a)),c._setIcon.call(s,this,e),c._target.call(s,null,t),s.opt.mouseover&&s.opt.mouseover.call(s,null)})},_buildScoreField:function(){return l("<input />",{name:this.opt.scoreName,type:"hidden"}).appendTo(this)},_createCancel:function(){var t=this.opt.path+this.opt.cancelOff,a=l("<"+this.opt.starType+" />",{title:this.opt.cancelHint,class:this.opt.cancelClass});"img"===this.opt.starType?a.attr({src:t,alt:"x"}):a.attr("data-alt","x").addClass(t),"left"===this.opt.cancelPlace?this.self.prepend("&#160;").prepend(a):this.self.append("&#160;").append(a),this.cancel=a},_createScore:function(){var t=l(this.opt.targetScore);this.score=t.length?t:c._buildScoreField.call(this)},_createStars:function(){for(var t=1;t<=this.opt.number;t++){var a=c._nameForIndex.call(this,t),e={alt:t,src:this.opt.path+this.opt[a]};"img"!==this.opt.starType&&(e={"data-alt":t,class:e.src}),e.title=c._getHint.call(this,t),l("<"+this.opt.starType+" />",e).appendTo(this),this.opt.space&&this.self.append(t<this.opt.number?"&#160;":"")}this.stars=this.self.children(this.opt.starType)},_error:function(t){l(this).text(t),l.error(t)},_fill:function(t){for(var a=0,e=1;e<=this.stars.length;e++){var s,i=this.stars[e-1],o=c._turnOn.call(this,e,t);if(this.opt.iconRange&&this.opt.iconRange.length>a){var r=this.opt.iconRange[a];s=c._getRangeIcon.call(this,r,o),e<=r.range&&c._setIcon.call(this,i,s),e===r.range&&a++}else s=this.opt[o?"starOn":"starOff"],c._setIcon.call(this,i,s)}},_getRangeIcon:function(t,a){return a?t.on||this.opt.starOn:t.off||this.opt.starOff},_getScoreByPosition:function(t,a){var e=parseInt(a.alt||a.getAttribute("data-alt"),10);if(this.opt.half){var s=c._getSize.call(this),i=parseFloat((t.pageX-l(a).offset().left)/s);e=this.opt.precision?e-1+i:e-1+(.5<i?1:.5)}return e},_getSize:function(){var t;return(t="img"===this.opt.starType?this.stars[0].width:parseFloat(this.stars.eq(0).css("font-size")))||c._error.call(this,"Could not be possible get the icon size!"),t},_turnOn:function(t,a){return this.opt.single?t===a:t<=a},_getHint:function(t){var a=this.opt.hints[t-1];return""===a?"":a||t},_lock:function(){var t=parseInt(this.score.val(),10),a=t?c._getHint.call(this,t):this.opt.noRatedMsg;this.style.cursor="",this.title=a,this.score.prop("readonly",!0),this.stars.prop("title",a),this.cancel&&this.cancel.hide(),this.self.data("readonly",!0)},_nameForIndex:function(t){return this.opt.score&&this.opt.score>=t?"starOn":"starOff"},_roundStars:function(t){var a=(t%1).toFixed(2);if(a>this.opt.round.down){var e="starOn";this.opt.halfShow&&a<this.opt.round.up?e="starHalf":a<this.opt.round.full&&(e="starOff");var s=this.opt[e],i=this.stars[Math.ceil(t)-1];c._setIcon.call(this,i,s)}},_setIcon:function(t,a){t["img"===this.opt.starType?"src":"className"]=this.opt.path+a},_setTarget:function(t,a){a&&(a=this.opt.targetFormat.toString().replace("{score}",a)),t.is(":input")?t.val(a):t.html(a)},_target:function(t,a){if(this.opt.target){var e=l(this.opt.target);e.length||c._error.call(this,"Target selector invalid or missing!");var s=a&&"mouseover"===a.type;if(void 0===t)t=this.opt.targetText;else if(null===t)t=s?this.opt.cancelHint:this.opt.targetText;else{"hint"===this.opt.targetType?t=c._getHint.call(this,Math.ceil(t)):this.opt.precision&&(t=parseFloat(t).toFixed(1));var i=a&&"mousemove"===a.type;s||i||this.opt.targetKeep||(t=this.opt.targetText)}c._setTarget.call(this,e,t)}},_unlock:function(){this.style.cursor="pointer",this.removeAttribute("title"),this.score.removeAttr("readonly"),this.self.data("readonly",!1);for(var t=0;t<this.opt.number;t++)this.stars[t].title=c._getHint.call(this,t+1);this.cancel&&this.cancel.css("display","")},cancel:function(a){return this.each(function(){var t=l(this);!0!==t.data("readonly")&&(c[a?"click":"score"].call(t,null),this.score.removeAttr("value"))})},click:function(t){return this.each(function(){!0!==l(this).data("readonly")&&(c._apply.call(this,t),this.opt.click&&this.opt.click.call(this,t,l.Event("click")),c._target.call(this,t))})},destroy:function(){return this.each(function(){var t=l(this),a=t.data("raw");a?t.off(".um_raty").empty().css({cursor:a.style.cursor}).removeData("readonly"):t.data("raw",t.clone()[0])})},getScore:function(){var t,a=[];return this.each(function(){t=this.score.val(),a.push(t?+t:void 0)}),1<a.length?a:a[0]},move:function(n){return this.each(function(){var t=parseInt(n,10),a=l(this).data("options"),e=(+n).toFixed(1).split(".")[1];t>=a.number&&(t=a.number-1,e=10);var s=c._getSize.call(this)/10,i=l(this.stars[t]),o=i.offset().left+s*parseInt(e,10),r=l.Event("mousemove",{pageX:o});i.trigger(r)})},readOnly:function(a){return this.each(function(){var t=l(this);t.data("readonly")!==a&&(a?(t.off(".um_raty").children("img").off(".um_raty"),c._lock.call(this)):(c._binds.call(this),c._unlock.call(this)),t.data("readonly",a))})},reload:function(){return c.set.call(this,{})},score:function(){var t=l(this);return arguments.length?c.setScore.apply(t,arguments):c.getScore.call(t)},set:function(s){return this.each(function(){var t=l(this),a=t.data("options"),e=l.extend({},a,s);t.um_raty(e)})},setScore:function(t){return this.each(function(){!0!==l(this).data("readonly")&&(c._apply.call(this,t),c._target.call(this,t))})}};l.fn.um_raty=function(t){return c[t]?c[t].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof t&&t?void l.error("Method "+t+" does not exist!"):c.init.apply(this,arguments)},l.fn.um_raty.defaults={cancel:!1,cancelClass:"raty-cancel",cancelHint:"Cancel this rating!",cancelOff:"cancel-off.png",cancelOn:"cancel-on.png",cancelPlace:"left",click:void 0,half:!1,halfShow:!0,hints:["bad","poor","regular","good","gorgeous"],iconRange:void 0,mouseout:void 0,mouseover:void 0,noRatedMsg:"Not rated yet!",number:5,numberMax:20,path:void 0,precision:!1,readOnly:!1,round:{down:.25,full:.6,up:.76},score:void 0,scoreName:"score",single:!1,space:!0,starHalf:"star-half.png",starOff:"star-off.png",starOn:"star-on.png",starType:"img",target:void 0,targetFormat:"{score}",targetKeep:!1,targetScore:void 0,targetText:"",targetType:"hint"}}(jQuery);