/**
 * Star Rating - jQuery plugin
 *
 * Copyright (c) 2007 Wil Stuckey
 * Modified by John Resig
 * Revamped by Josh Kline
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 */

(function($){$.fn.extend({rating:function(options){if(options=='value'){return $.data(this[0],'rating').value(arguments[1]);}var args=Array.prototype.slice.call(arguments,1);return this.each(function(){if(typeof options==typeof''){var plugin=$.data(this,'rating');plugin[options].apply(plugin,args);}else if(!$.data(this,'rating')){new $.fn.rating.impl(this,options);}});}});$.fn.rating.defaults={'container_class':'rating','container_disabled_class':'rating_disabled','cancel_class':'cancel','cancel_title':'Cancel Rating','cancel_href':'#0','cancel_text':'Cancel Rating','cancel_hover_class':'on','star_class':'star','star_title':function(option_elem){return option_elem.text;},'star_href':function(option_elem){return'#'+option_elem.value;},'star_text':function(option_elem){return option_elem.value;},'star_on_class':'on','star_hover_class':'hover','onchange':null};$.fn.rating.impl=function(select,options){var self=this;this.select=$(select);$.data(select,'rating',this);this.options=options=$.extend({},$.fn.rating.defaults,options);if(options.initial_value==undefined){options.initial_value=this.select.val();}if(isNaN(parseFloat(options.initial_value))){options.initial_value=0;}$(select).bind('setData.rating',function(event,key,value){self.options[key]=value;}).bind('getData.rating',function(event,key){return self.options[key];});this.container=$('<div>').addClass(options.container_class).insertAfter(this.select);this.select.hide().find('option').each(function(){self.container.append(this.value=='0'?new_cancel():new_star(this));});this.enabled=true;this.stars=this.container.find('.'+options.star_class).mouseover(drainFill).mouseout(drainReset).click(click);this.stars.find('a').focus(function(){drainFill.call(this.parentNode);}).blur(function(){drainReset.call(this.parentNode);});this.cancel=this.container.find('.'+options.cancel_class).mouseover(drainAdd).mouseout(resetRemove).click(click);this.cancel.find('a').focus(function(){drainAdd.call(this.parentNode);}).blur(function(){resetRemove.call(this.parentNode);});this.reset_to_initial();function new_star(option_elem){return $(document.createElement('div')).addClass(self.options.star_class).append($(document.createElement('a')).attr({href:self.options.star_href(option_elem),title:self.options.star_title(option_elem)}).text(options.star_text(option_elem)));}function new_cancel(){return $(document.createElement('div')).addClass(self.options.cancel_class).append($(document.createElement('a')).attr({href:self.options.cancel_href,title:self.options.cancel_title}).text(options.cancel_text));}function drainFill(){if(self.enabled){self.drain();self.fill(this);}}function drainReset(){if(self.enabled){self.drain();self.reset();}}function resetRemove(){if(self.enabled){self.reset();$(this).removeClass(self.options.cancel_hover_class);}}function drainAdd(){if(self.enabled){self.drain();$(this).addClass(self.options.cancel_hover_class);}}function click(event){if(self.enabled){self.value(self.stars.index(this)+1);}event.preventDefault();}};$.extend($.fn.rating.impl.prototype,{drain:function(){this.stars.removeClass(this.options.star_on_class+' '+this.options.star_hover_class);},fill:function(current_star){this.stars.find('a').css('width','100%');this.stars.slice(0,this.stars.index(current_star)+1).addClass(this.options.star_hover_class);},reset:function(){var value=this.value();var index=parseInt(value);var percent=parseInt(value%1*100);this.stars.children('a').css('width','100%');this.stars.slice(0,index).addClass(this.options.star_on_class);if(percent>0){this.stars.slice(index,index+1).addClass(this.options.star_on_class).children('a').css('width',percent+'%');}},reset_to_initial:function(){this.value(this.options.initial_value);},value:function(new_value,prevent_callback){if(new_value!=undefined){var old_value=this.value();this.select.val(new_value);this.display_value=parseFloat(new_value);this.drain();this.reset();if(old_value!=undefined&&old_value!=new_value&&this.options.onchange&&!prevent_callback){this.options.onchange.call(this,old_value);}}return this.display_value;},disable:function(){this.container.addClass(this.options.container_disabled_class);this.enabled=false;},enable:function(){this.container.removeClass(this.options.container_disabled_class);this.enabled=true;},destroy:function(){this.container.remove();this.select.removeData('rating').show();}});if($.browser.msie){document.execCommand('BackgroundImageCache',false,true);}})(jQuery);
