;if(window.jQuery) (function($){
// IE6 Background Image Fix
	if ($.browser.msie) try { document.execCommand("BackgroundImageCache", false, true)} catch(e) { }
	
	$.rating = {
		cancel: 'Cancel Rating',   // advisory title for the 'cancel' link
		cancelValue: '',           // value to submit when user click the 'cancel' link
		split: 2,                  // split the star into how many parts?
		starWidth: 14,
		groups: {},// allows multiple star ratings on one page
		event: {// plugin event handlers
			fill: function(n, el, settings, state){ // fill to the current mouse position.
				this.drain(n);
				$(el).prevAll('.star_group_'+n).andSelf().addClass('star_'+(state || 'hover'));
				val = $(el).children('a').attr('rel'); 
			},
			drain: function(n, el, settings) { // drain all the stars.
				$.rating.groups[n].valueElem.siblings('.star_group_'+n).removeClass('star_on').removeClass('star_hover');
			},
			reset: function(n, el, settings){ // Reset the stars to the default index.
				if(!$($.rating.groups[n].current).is('.cancel')) $($.rating.groups[n].current).prevAll('.star_group_'+n).andSelf().addClass('star_on');
				val = $(el).children('a').attr('rel');
			},
			click: function(n, el, settings){ // Selected a star or cancelled
				$.rating.groups[n].current = el;
				val =  $(el).children('a').attr('rel');
				if (settings.no_ajax == false) xmlhttp_request('/mp', val, '');
				$.rating.groups[n].valueElem.val(val);
				$.rating.event.drain(n, el, settings);
				$.rating.event.reset(n, el, settings);
				$(el).parent('div').addClass('yellow');
			}
		}
	};
	
	$.fn.rating = function(instanceSettings){
		if($(this).length==0) return this; // quick fail
		
		this.each(function(){
			var n = (this.name || 'unnamed-rating').replace(/\[|\]/, "_");
			$.rating.groups[n] = {count: 10};
			$.rating.groups[n].readOnly = false;
			$.rating.groups[n].valueElem = $(this);
			$.rating.groups[n].current = $(this).siblings('div.current');
		});
		return this; // dont break the chain...
	};
})(jQuery);
