/*!
* jQuery Raty - A Star Rating Plugin - http://wbotelhos.com/raty
*
* @author Washington Botelho
* @twitter wbotelhos
* @version 1.4.3
*
* Licensed under The MIT License
* http://opensource.org/licenses/mit-license.php
*
*/
(function(e){function t(t,i,s){var f=t.attr("id"),l=e("input#"+f+"-score"),c=t.children("span."+f);t.mouseleave(function(){var r=e("input#"+this.id+"-score");o(t,r.val(),i);n(s,r,i)});c.bind(i.half?"mousemove":"mouseover",function(n){r(f,e(this).attr("alt"),i);if(i.half){var o=parseFloat(((n.pageX-e(this).offset().left)/i.size).toFixed(1));o=o>=0&&o<.5?.5:1;t.data("score",parseFloat(e(this).attr("alt"))+o-1);a(t,t.data("score"),i)}else{r(f,e(this).attr("alt"),i)}u(s,e(this).attr("alt"),i)}).click(function(n){l.val(i.half?t.data("score"):e(this).attr("alt"));if(i.click){i.click.apply(t,[l.val(),n])}})}function n(e,t,n){if(e!==null){var r="";if(n.targetKeep){r=t.val();if(n.targetType=="hint"){if(t.val()==""&&n.cancel){r=n.cancelHint}else{r=n.hintList[Math.ceil(t.val())-1]}}}if(s(e)){e.val(r)}else{e.html(r)}}}function r(t,n,r){var i=e("span."+t).length,s=0,o=0,u,a=r.starOn,f=r.starOff;for(var l=1;l<=i;l++){u=e("span#"+t+"-"+l);if(l<=n){if(r.iconRange&&r.iconRange.length>s){a=r.iconRange[s][0];o=r.iconRange[s][1];if(l<=o){u.removeClass(f).addClass(a)}if(l==o){s++}}else{u.removeClass(f).addClass(a)}}else{u.removeClass(a).addClass(f)}}}function i(e,t,n){var r="";if(t!=0){t=parseInt(t);r=t>0&&n.number<=n.hintList.length&&n.hintList[t-1]!==null?n.hintList[t-1]:t}else{r=n.noRatedMsg}e.attr("title",r).children("span").attr("title",r)}function s(e){return e.is("input")||e.is("select")||e.is("textarea")}function o(t,n,s){var o=t.attr("id");if(isNaN(parseInt(n))){t.children("span."+o).removeClass(s.starOn).addClass(s.starOff);e("input#"+o+"-score").removeAttr("value");return}if(n<0){n=0}else if(n>s.number){n=s.number}r(o,n,s);if(n>0){e("input#"+o+"-score").val(n);if(s.half){a(t,n,s)}}if(s.readOnly||t.css("cursor")=="default"){i(t,n,s)}}function u(e,t,n){if(e!==null){var r=t;if(n.targetType=="hint"){if(t==0&&n.cancel){r=n.cancelHint}else{r=n.hintList[t-1]}}if(s(e)){e.val(r)}else{e.html(r)}}}function a(t,n,r){var i=t.attr("id"),s=Math.ceil(n),o=(s-n).toFixed(1);if(o>.25&&o<=.75){s=s-.5;e("span#"+i+"-"+Math.ceil(s)).removeClass(starOff).removeClass(starOn).addClass(starHalf)}else if(o>.75){s--}else{e("span#"+i+"-"+s).removeClass(starOff).addClass(starOn)}}function f(t,n,r){var i=undefined;if(n==undefined){l("Specify an ID or class to be the target of the action.");return}if(n){if(n.indexOf(".")>=0){var s;return e(n).each(function(){s="#"+e(this).attr("id");if(r=="start"){e.fn.raty.start(t,s)}else if(r=="click"){e.fn.raty.click(t,s)}else if(r=="readOnly"){e.fn.raty.readOnly(t,s)}})}i=e(n);if(!i.length){l('"'+n+'" is a invalid identifier for the public funtion $.fn.raty.'+r+"().");return}}return i}function l(e){if(window.console&&window.console.log){window.console.log(e)}}e.fn.raty=function(n){if(this.length==0){return}else if(this.length>1){return this.each(function(){e.fn.raty.apply(e(this),[n])})}var s=e.extend({},e.fn.raty.defaults,n),o=e(this),f=this.attr("id"),c=0,h=s.starOn,p="",d=s.target,v=s.width?s.width:s.number*s.size+s.number*4;if(f===undefined){f="raty-"+o.index();o.attr("id",f)}if(s.number>20){s.number=20}else if(s.number<0){s.number=0}o.data("options",s);if(!isNaN(parseInt(s.start))&&s.start>0){c=s.start>s.number?s.number:s.start}for(var m=1;m<=s.number;m++){h=c>=m?s.starOn:s.starOff;p=m<=s.hintList.length&&s.hintList[m-1]!==null?s.hintList[m-1]:m;o.append('<span id="'+f+"-"+m+'" alt="'+m+'" title="'+p+'" class="'+f+" "+h+'"></span>').append(m<s.number?" ":"")}if(s.iconRange&&c>0){r(f,c,s)}var g=e("<input/>",{id:f+"-score",type:"hidden",name:s.scoreName}).appendTo(o);if(c>0){g.val(c)}if(s.half){a(o,e("input#"+f+"-score").val(),s)}if(!s.readOnly){if(d!==null){d=e(d);if(d.length==0){l("Target selector invalid or missing!")}}if(s.cancel){var y=e("span."+f),b='<span alt="x" title="'+s.cancelHint+'" class="button-cancel '+s.cancelOff+'"/>';if(s.cancelPlace=="left"){o.prepend(b+" ")}else{o.append(" ").append(b)}e("#"+f+" span.button-cancel").mouseenter(function(){e(this).removeClass(s.cancelOff).addClass(s.cancelOn);y.removeClass(s.starOn).addClass(s.starOff);u(d,"",s)}).mouseleave(function(){e(this).removeClass(s.cancelOn).addClass(s.cancelOff);o.mouseout()}).click(function(t){e("input#"+f+"-score").removeAttr("value");if(s.click){s.click.apply(o,[null,t])}});o.css("width",v+s.size+4)}else{o.css("width",v)}o.css("cursor","pointer");t(o,s,d)}else{o.css("cursor","default");i(o,c,s)}return o};e.fn.raty.cancel=function(t,n){var r=n===undefined?false:true;if(r){return e.fn.raty.click("",t,"cancel")}else{return e.fn.raty.start("",t,"cancel")}};e.fn.raty.click=function(t,n){var r=f(t,n,"click"),i=e(n).data("options");if(n.indexOf(".")>=0){return}o(r,t,i);if(i.click){i.click.apply(r,[t])}else{l('You must add the "click: function(score, evt) { }" callback.')}return r};e.fn.raty.readOnly=function(n,r){var i=f(n,r,"readOnly"),s=e(r).data("options"),o=i.children("span.button-cancel");if(r.indexOf(".")>=0){return}if(o[0]){n?o.hide():o.show()}if(n){e("span."+i.attr("id")).unbind();i.css("cursor","default").unbind()}else{t(i,s);i.css("cursor","pointer")}return i};e.fn.raty.start=function(t,n){var r=f(t,n,"start"),i=e(n).data("options");if(n.indexOf(".")>=0){return}o(r,t,i);return r};e.fn.raty.defaults={cancel:false,cancelHint:"cancel this rating!",cancelOff:"raty_cancel_off",cancelOn:"raty_cancel_on",cancelPlace:"left",click:null,half:false,hintList:["bad","poor","regular","good","gorgeous"],noRatedMsg:"not rated yet",number:5,iconRange:[],readOnly:false,scoreName:"score",size:16,starHalf:"raty_star_half",starOff:"raty_star_off",starOn:"raty_star_on",start:0,target:null,targetKeep:false,targetType:"hint",width:null}})(jQuery)