/**
 * Simple rating script
 * 
 * Visit http://rightjs.org/ui/rater for details
 *
 * Copyright (C) 2009-2010 Nikolay V. Nemshilov
 */
if (!self.RightJS) throw "Gimme RightJS";
var Rater=new Class(Observer,{extend:{EVENTS:$w('change hover send'),Options:{size:5,value:null,update:null,disabled:false,disableOnVote:false,url:null,param:'rate',Xhr:null},rescan:function(s){}},initialize:function(){var a=$A(arguments);this.element=(a[0]&&!isHash(a[0]))?$(a[0]):null;this.$super(isHash(a.last())?a.last():this.element?eval('('+this.element.get('data-rater-options')+')'):null);if(!this.element)this.element=this.build();if(!this.options.value)this.options.value=this.element.select('.right-rater-glow').length;this.element._rater=this.init()},setValue:function(v){if(!this.disabled()){v=isString(v)?v.toInt():v;v=isNumber(v)?v.round():0;if(v>this.options.size)v=this.options.size;else if(v<0)v=0;this.highlight(v);if(this.value!=v)this.fire('change',this.value=v,this)}return this},getValue:function(){return this.value},insertTo:function(e,p){this.element.insertTo(e,p);return this},assignTo:function(b){var a=function(e,v){if(e=$(e)){if(v===undefined||v===null)v='';e[e.setValue?'setValue':'update'](''+v)}}.curry(b);var c=function(e,o){var e=$(e);if(e&&e.onChange)e.onChange(function(){this.setValue(e.value)}.bind(o))}.curry(b);if($(b)){a(this.value);c(this)}else document.onReady(function(){a(this.value);c(this)}.bind(this));return this.onChange(a)},send:function(){if(this.options.url){new Xhr(this.options.url,this.options.Xhr).send(this.options.param+"="+this.value);this.fire('send',this.value,this)}return this},disable:function(){this.element.addClass('right-rater-disabled');return this},enable:function(){this.element.removeClass('right-rater-disabled');return this},disabled:function(){return this.element.hasClass('right-rater-disabled')},hovered:function(i){if(!this.disabled()){this.highlight(i+1);this.fire('hover',i+1,this)}},clicked:function(i){this.setValue(i+1);if(this.options.disableOnVote)this.disable();this.send()},leaved:function(){this.setValue(this.value)},highlight:function(n){this.stars.each(function(e,a){e[n-1<a?'removeClass':'addClass']('right-rater-glow')})},init:function(){this.stars=this.element.subNodes();this.stars.each(function(e,i){e.onMouseover(this.hovered.bind(this,i)).onClick(this.clicked.bind(this,i))},this);this.element.onMouseout(this.leaved.bind(this));this.setValue(this.options.value);if(this.options.disabled)this.disable();if(this.options.update)this.assignTo(this.options.update);return this},build:function(){var e=$E('div',{'class':'right-rater'});this.options.size.times(function(){e.insert($E('div',{html:'&#9733;'}))});return e}});document.onMouseover(function(a){var t=a.target,e=[t].concat(t.parents()).first('hasClass','right-rater');if(e){var r=e._rater||new Rater(e);if(t.parentNode===e)t.fire('mouseover')}});document.write("<style type=\"text/css\">div.right-rater,div.right-rater div{margin:0;padding:0;background:none;border:none;display:inline-block;*display:inline;*zoom:1;font-family:Arial;font-size:110%}div.right-rater{width:6em;height:1em;vertical-align:middle}div.right-rater div{float:left;width:1em;height:1em;line-height:1em;text-align:center;cursor:pointer;color:#888}div.right-rater div.right-rater-glow{color:brown;text-shadow:#666 .05em .05em .15em}div.right-rater-disabled div{cursor:default}</style>");