rating_sended = 0;
if (window.jQuery)
	( function($) {
		$.fn.metadata = function(a) {
			return $.fn.rating.get(this[0], a)
		};
		if ($.browser.msie)
			try {
				document.execCommand("BackgroundImageCache", false, true)
			} catch (e) {
			}
		;
		$.fn.rating = function(i) {
			if (this.length == 0)
				return this;
			if (typeof arguments[0] == 'string') {
				if (this.length > 1) {
					var j = arguments;
					return this.each( function() {
						$.fn.rating.apply($(this), j)
					})
				}
				;
				$.fn.rating[arguments[0]].apply(this, $.makeArray(arguments)
						.slice(1)
						|| []);
				return this
			}
			;
			var i = $.extend( {}, $.fn.rating.options, i || {});
			$.fn.rating.calls++;
			this
					.not('.star-rating-applied')
					.addClass('star-rating-applied')
					.each(
							function() {
								var a, input = $(this);
								var b = (this.name || 'unnamed-rating')
										.replace(/\[|\]/g, '_').replace(
												/^\_+|\_+$/g, '');
								var c = $(this.form || document.body);
								var d = c.data('rating');
								if (!d || d.call != $.fn.rating.calls)
									d = {
										count : 0,
										call : $.fn.rating.calls
									};
								var e = d[b];
								if (e)
									a = e.data('rating');
								if (e && a)
									a.count++;
								else {
									a = $.extend(input.metadata(), {
										count : 0,
										stars : [],
										inputs : []
									});
									a.serial = d.count++;
									e = $('<span class="star-rating-control"/>');
									input.before(e);
									e.addClass('rating-to-be-drawn');
									if (input.attr('disabled'))
										a.readOnly = true;
									e.append(a.cancel = $(
											'<div class="rating-cancel"><a title="'
													+ a.cancel + '">'
													+ a.cancelValue
													+ '</a></div>').mouseover(
											function() {
												$(this).rating('drain');
												$(this).addClass(
														'star-rating-hover')
											}).mouseout(
											function() {
												$(this).rating('draw');
												$(this).removeClass(
														'star-rating-hover')
											}).click( function() {
										$(this).rating('select')
									}).data('rating', a))
								}
								;
								var f = $('<div class="star-rating rater-'
										+ a.serial + '"><a title="'
										+ (this.title || this.value) + '">'
										+ this.value + '</a></div>');
								e.append(f);
								if (this.id)
									f.attr('id', this.id);
								if (this.className)
									f.addClass(this.className);
								if (a.half)
									a.split = 2;
								if (typeof a.split == 'number' && a.split > 0) {
									var g = ($.fn.width ? f.width() : 0)
											|| a.starWidth;
									var h = (a.count % a.split), spw = Math
											.floor(g / a.split);
									f.width(spw).find('a').css( {
										'margin-left' : '-' + (h * spw) + 'px'
									})
								}
								;
								if (a.readOnly)
									f.addClass('star-rating-readonly');
								else
									f.addClass('star-rating-live').mouseover(
											function() {
												$(this).rating('fill');
												$(this).rating('focus')
											}).mouseout( function() {
										$(this).rating('draw');
										$(this).rating('blur')
									}).click( function() {
										$(this).rating('select')
									});
								if (this.checked)
									a.current = f;
								input.hide();
								input.change( function() {
									$(this).rating('select')
								});
								f.data('rating.input', input.data(
										'rating.star', f));
								a.stars[a.stars.length] = f[0];
								a.inputs[a.inputs.length] = input[0];
								a.rater = d[b] = e;
								a.context = c;
								input.data('rating', a);
								e.data('rating', a);
								f.data('rating', a);
								c.data('rating', d)
							});
			$('.rating-to-be-drawn').rating('draw').removeClass(
					'rating-to-be-drawn');
			return this
		};
		$.extend($.fn.rating, {
			calls : 0,
			focus : function() {
				var a = this.data('rating');
				if (!a)
					return this;
				if (!a.focus)
					return this;
				var b = $(this).data('rating.input')
						|| $(this.tagName == 'INPUT' ? this : null);
				if (a.focus)
					a.focus.apply(b[0], [ b.val(),
							$('a', b.data('rating.star'))[0] ])
			},
			blur : function() {
				var a = this.data('rating');
				if (!a)
					return this;
				if (!a.blur)
					return this;
				var b = $(this).data('rating.input')
						|| $(this.tagName == 'INPUT' ? this : null);
				if (a.blur)
					a.blur.apply(b[0], [ b.val(),
							$('a', b.data('rating.star'))[0] ])
			},
			fill : function() {
				var a = this.data('rating');
				if (!a)
					return this;
				if (a.readOnly)
					return;
				this.rating('drain');
				this.prevAll().andSelf().filter('.rater-' + a.serial).addClass(
						'star-rating-hover')
			},
			drain : function() {
				var a = this.data('rating');
				if (!a)
					return this;
				if (a.readOnly)
					return;
				a.rater.children().filter('.rater-' + a.serial).removeClass(
						'star-rating-on').removeClass('star-rating-hover')
			},
			draw : function() {
				var a = this.data('rating');
				if (!a)
					return this;
				this.rating('drain');
				if (a.current) {
					a.current.data('rating.input').attr('checked', 'checked');
					a.current.prevAll().andSelf().filter('.rater-' + a.serial)
							.addClass('star-rating-on')
				} else
					$(a.inputs).removeAttr('checked');
				a.cancel[a.readOnly || a.required ? 'hide' : 'show']();
				this.siblings()[a.readOnly ? 'addClass' : 'removeClass']
						('star-rating-readonly')
			},
			select : function(b, c, f) {
				var d = this.data('rating');
				if (!d)
					return this;
				if (d.readOnly)
					return;
				d.current = null;
				if (typeof b != 'undefined') {
					if (typeof b == 'number')
						return $(d.stars[b]).rating('select');
					if (typeof b == 'string')
						$.each(d.stars, function() {
							if ($(this).data('rating.input').val() == b)
								$(this).rating('select')
						})
				} else
					d.current = this[0].tagName == 'INPUT' ? this
							.data('rating.star') : (this
							.is('.rater-' + d.serial) ? this : null);
				this.data('rating', d);
				this.rating('draw');
				var e = $(d.current ? d.current.data('rating.input') : null);
				if (d.callback)
					d.callback.apply(e[0], [ e.val(), $('a', d.current)[0] ]);
				eval("d.data." + d.value_el + " = e.val();");
				if (d.url && !rating_sended && !f) {
					if (d.method == "post") {
						$.post(d.url, d.data, function(a) {
							if (d.hs) {
								$("#" + d.eofurl).hide()
							}
							$("#" + d.eofurl).empty();
							$("#" + d.eofurl).append(a);
							if (d.hs) {
								$("#" + d.eofurl).slideToggle(d.speed)
							}
						})
					} else {
						$.get(d.url, d.data, function(a) {
							if (d.hs) {
								$("#" + d.eofurl).hide()
							}
							$("#" + d.eofurl).empty();
							$("#" + d.eofurl).append(a);
							if (d.hs) {
								$("#" + d.eofurl).slideToggle(d.speed)
							}
						})
					}
				}
				rating_sended = 1
			},
			readOnly : function(a, b) {
				var c = this.data('rating');
				if (!c)
					return this;
				c.readOnly = a || a == undefined ? true : false;
				if (b)
					$(c.inputs).attr("disabled", "disabled");
				else
					$(c.inputs).removeAttr("disabled");
				this.data('rating', c);
				this.rating('draw')
			},
			disable : function() {
				this.rating('readOnly', true, true)
			},
			enable : function() {
				this.rating('readOnly', false, false)
			},
			defaults : {
				type : 'class',
				name : 'metadata',
				cre : /({.*})/,
				single : 'metadata'
			},
			setType : function(a, b) {
				this.defaults.type = a;
				this.defaults.name = b
			},
			get : function(a, b) {
				var c = $.extend( {}, this.defaults, b);
				if (!c.single.length)
					c.single = 'metadata';
				var d = $.data(a, c.single);
				if (d)
					return d;
				d = "{}";
				if (c.type == "class") {
					var m = c.cre.exec(a.className);
					if (m)
						d = m[1]
				} else if (c.type == "elem") {
					if (!a.getElementsByTagName)
						return;
					var e = a.getElementsByTagName(c.name);
					if (e.length)
						d = $.trim(e[0].innerHTML)
				} else if (a.getAttribute != undefined) {
					var f = a.getAttribute(c.name);
					if (f)
						d = f
				}
				if (d.indexOf('{') < 0)
					d = "{" + d + "}";
				d = eval("(" + d + ")");
				$.data(a, c.single, d);
				return d
			}
		});
		$.fn.rating.options = {
			cancel : 'Cancel Rating',
			cancelValue : '',
			split : 0,
			url : '',
			data : {},
			value_el : 'rate',
			eofurl : '',
			method : 'post',
			hs : 1,
			speed : 'medium',
			starWidth : 16,
			half : false,
			required : false,
			readOnly : false,
			focus : function() {
			},
			blur : function() {
			},
			callback : function() {
			}
		};
		$( function() {
			$('input[type=radio].star').rating()
		})
	})(jQuery);
