/*!
 * jQuery Raty - A Star Rating Plugin
 *
 * Licensed under The MIT License
 *
 * @author  : Washington Botelho
 * @doc     : http://wbotelhos.com/raty
 * @version : 2.5.2
 *
 */
(function(c){var d={init:function(a){return this.each(function(){d.destroy.call(this);this.opt=c.extend(true,{},c.fn.raty.defaults,a);var i=c(this),b=["number","readOnly","score","scoreName"];d._callback.call(this,b);if(this.opt.precision){d._adjustPrecision.call(this)}this.opt.number=d._between(this.opt.number,0,this.opt.numberMax);this.opt.path=this.opt.path||"";if(this.opt.path&&this.opt.path.charAt(this.opt.path.length-1)!=="/"){this.opt.path+="/"}this.stars=d._createStars.call(this);this.score=d._createScore.call(this);d._apply.call(this,this.opt.score);var h=this.opt.space?4:0,j=this.opt.width||(this.opt.number*this.opt.size+this.opt.number*h);if(this.opt.cancel){this.cancel=d._createCancel.call(this);j+=(this.opt.size+h)}if(this.opt.readOnly){d._lock.call(this)}else{i.css("cursor","pointer");d._binds.call(this)}if(this.opt.width!==false){i.css("width",j)}d._target.call(this,this.opt.score);i.data({settings:this.opt,raty:true})})},_adjustPrecision:function(){this.opt.targetType="score";this.opt.half=true},_apply:function(a){if(a&&a>0){a=d._between(a,0,this.opt.number);this.score.val(a)}d._fill.call(this,a);if(a){d._roundStars.call(this,a)}},_between:function(a,b,f){return Math.min(Math.max(parseFloat(a),b),f)},_binds:function(){if(this.cancel){d._bindCancel.call(this)}d._bindClick.call(this);d._bindOut.call(this);d._bindOver.call(this)},_bindCancel:function(){d._bindClickCancel.call(this);d._bindOutCancel.call(this);d._bindOverCancel.call(this)},_bindClick:function(){var b=this,a=c(b);b.stars.on("click.raty",function(f){b.score.val((b.opt.half||b.opt.precision)?a.data("score"):this.alt);if(b.opt.click){b.opt.click.call(b,parseFloat(b.score.val()),f)}})},_bindClickCancel:function(){var a=this;a.cancel.on("click.raty",function(b){a.score.removeAttr("value");if(a.opt.click){a.opt.click.call(a,null,b)}})},_bindOut:function(){var a=this;c(this).on("mouseleave.raty",function(f){var b=parseFloat(a.score.val())||undefined;d._apply.call(a,b);d._target.call(a,b,f);if(a.opt.mouseout){a.opt.mouseout.call(a,b,f)}})},_bindOutCancel:function(){var a=this;a.cancel.on("mouseleave.raty",function(b){c(this).attr("src",a.opt.path+a.opt.cancelOff);if(a.opt.mouseout){a.opt.mouseout.call(a,a.score.val()||null,b)}})},_bindOverCancel:function(){var a=this;a.cancel.on("mouseover.raty",function(b){c(this).attr("src",a.opt.path+a.opt.cancelOn);a.stars.attr("src",a.opt.path+a.opt.starOff);d._target.call(a,null,b);if(a.opt.mouseover){a.opt.mouseover.call(a,null)}})},_bindOver:function(){var f=this,b=c(f),a=f.opt.half?"mousemove.raty":"mouseover.raty";f.stars.on(a,function(k){var j=parseInt(this.alt,10);if(f.opt.half){var l=parseFloat((k.pageX-c(this).offset().left)/f.opt.size),e=(l>0.5)?1:0.5;j=j-1+e;d._fill.call(f,j);if(f.opt.precision){j=j-e+l}d._roundStars.call(f,j);b.data("score",j)}else{d._fill.call(f,j)}d._target.call(f,j,k);if(f.opt.mouseover){f.opt.mouseover.call(f,j,k)}})},_callback:function(b){for(var a in b){if(typeof this.opt[b[a]]==="function"){this.opt[b[a]]=this.opt[b[a]].call(this)}}},_createCancel:function(){var a=c(this),f=this.opt.path+this.opt.cancelOff,b=c("<img />",{src:f,alt:"x",title:this.opt.cancelHint,"class":"raty-cancel"});if(this.opt.cancelPlace=="left"){a.prepend("&#160;").prepend(b)}else{a.append("&#160;").append(b)}return b},_createScore:function(){return c("<input />",{type:"hidden",name:this.opt.scoreName}).appendTo(this)},_createStars:function(){var b=c(this);for(var h=1;h<=this.opt.number;h++){var a=d._getHint.call(this,h),g=(this.opt.score&&this.opt.score>=h)?"starOn":"starOff";g=this.opt.path+this.opt[g];c("<img />",{src:g,alt:h,title:a}).appendTo(this);if(this.opt.space){b.append((h<this.opt.number)?"&#160;":"")}}return b.children("img")},_error:function(a){c(this).html(a);c.error(a)},_fill:function(s){var a=this,r=0;for(var q=1;q<=a.stars.length;q++){var p=a.stars.eq(q-1),b=a.opt.single?(q==s):(q<=s);if(a.opt.iconRange&&a.opt.iconRange.length>r){var n=a.opt.iconRange[r],o=n.on||a.opt.starOn,t=n.off||a.opt.starOff,i=b?o:t;if(q<=n.range){p.attr("src",a.opt.path+i)}if(q==n.range){r++}}else{var i=b?"starOn":"starOff";p.attr("src",this.opt.path+this.opt[i])}}},_getHint:function(a){var b=this.opt.hints[a-1];return(b==="")?"":(b||a)},_lock:function(){var a=parseInt(this.score.val(),10),b=a?d._getHint.call(this,a):this.opt.noRatedMsg;c(this).data("readonly",true).css("cursor","").attr("title",b);this.score.attr("readonly","readonly");this.stars.attr("title",b);if(this.cancel){this.cancel.hide()}},_roundStars:function(a){var b=(a-Math.floor(a)).toFixed(2);if(b>this.opt.round.down){var f="starOn";if(this.opt.halfShow&&b<this.opt.round.up){f="starHalf"}else{if(b<this.opt.round.full){f="starOff"}}this.stars.eq(Math.ceil(a)-1).attr("src",this.opt.path+this.opt[f])}},_target:function(a,g){if(this.opt.target){var b=c(this.opt.target);if(b.length===0){d._error.call(this,"Target selector invalid or missing!")}if(this.opt.targetFormat.indexOf("{score}")<0){d._error.call(this,'Template "{score}" missing!')}var h=g&&g.type=="mouseover";if(a===undefined){a=this.opt.targetText}else{if(a===null){a=h?this.opt.cancelHint:this.opt.targetText}else{if(this.opt.targetType=="hint"){a=d._getHint.call(this,Math.ceil(a))}else{if(this.opt.precision){a=parseFloat(a).toFixed(1)}}if(!h&&!this.opt.targetKeep){a=this.opt.targetText}}}if(a){a=this.opt.targetFormat.toString().replace("{score}",a)}if(b.is(":input")){b.val(a)}else{b.html(a)}}},_unlock:function(){c(this).data("readonly",false).css("cursor","pointer").removeAttr("title");this.score.removeAttr("readonly","readonly");for(var a=0;a<this.opt.number;a++){this.stars.eq(a).attr("title",d._getHint.call(this,a+1))}if(this.cancel){this.cancel.css("display","")}},cancel:function(a){return this.each(function(){if(c(this).data("readonly")!==true){d[a?"click":"score"].call(this,null);this.score.removeAttr("value")}})},click:function(a){return c(this).each(function(){if(c(this).data("readonly")!==true){d._apply.call(this,a);if(!this.opt.click){d._error.call(this,'You must add the "click: function(score, evt) { }" callback.')}this.opt.click.call(this,a,c.Event("click"));d._target.call(this,a)}})},destroy:function(){return c(this).each(function(){var a=c(this),b=a.data("raw");if(b){a.off(".raty").empty().css({cursor:b.style.cursor,width:b.style.width}).removeData("readonly")}else{a.data("raw",a.clone()[0])}})},getScore:function(){var a=[],b;c(this).each(function(){b=this.score.val();a.push(b?parseFloat(b):undefined)});return(a.length>1)?a:a[0]},readOnly:function(a){return this.each(function(){var b=c(this);if(b.data("readonly")!==a){if(a){b.off(".raty").children("img").off(".raty");d._lock.call(this)}else{d._binds.call(this);d._unlock.call(this)}b.data("readonly",a)}})},reload:function(){return d.set.call(this,{})},score:function(){return arguments.length?d.setScore.apply(this,arguments):d.getScore.call(this)},set:function(a){return this.each(function(){var g=c(this),b=g.data("settings"),h=c.extend({},b,a);g.raty(h)})},setScore:function(a){return c(this).each(function(){if(c(this).data("readonly")!==true){d._apply.call(this,a);d._target.call(this,a)}})}};c.fn.raty=function(a){if(d[a]){return d[a].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof a==="object"||!a){return d.init.apply(this,arguments)}else{c.error("Method "+a+" does not exist!")}}};c.fn.raty.defaults={cancel:false,cancelHint:"Cancel this rating!",cancelOff:"cancel-off.png",cancelOn:"cancel-on.png",cancelPlace:"left",click:undefined,half:false,halfShow:true,hints:["bad","poor","regular","good","gorgeous"],iconRange:undefined,mouseout:undefined,mouseover:undefined,noRatedMsg:"Not rated yet!",number:5,numberMax:20,path:"",precision:false,readOnly:false,round:{down:0.25,full:0.6,up:0.76},score:undefined,scoreName:"score",single:false,size:16,space:true,starHalf:"star-half.svg",starOff:"star-off.svg",starOn:"star-on.svg",target:undefined,targetFormat:"{score}",targetKeep:false,targetText:"",targetType:"hint",width:undefined}})(jQuery);