var sfRatings = new Class({
	Implements: Options,
	el: Class.empty,
	stars: Class.empty,
	options: {
		stars: 5,
		rating: 0,
		id: ''
	},
	initialize: function(ratingEl, starEls, options) {
		this.el = $(ratingEl);
		this.stars = starEls;
		
		// process options passed in
		this.setOptions(options);
		
		if (this.el) {
			this.stars.each(function(star, i) {
				star.onclick = function() {
					this.rate(i+1);
					return false;
				}.bind(this);
				star.addEvent('mouseover', function() {
					this.stars.each(function(jstar, j) {
						if (j<=i) {
							if (j<this.options.rating) jstar.addClass('staronhov');
							else jstar.addClass('starhov');
						} else {
							if (j<this.options.rating) jstar.removeClass('staronhov');
							else jstar.removeClass('starhov');
						}
					}, this);
				}.bind(this));
				star.addEvent('mouseout', function() {
					this.stars.each(function(jstar, j) {
						jstar.removeClass('staronhov');
						jstar.removeClass('starhov');
					}, this);
				}.bind(this));

			}, this);
			// if rating set in js options, apply now
			this.set(this.options.rating);
		}
	},
	rate: function(a) {
		if (a==this.options.rating) a=0;
		this.options.rating = a;
		new Request({
			url: '/includes/rate.php',
			method: 'post',
			link: 'cancel',
			onComplete: function(r) {
				if (r && r=='SUCCESS') {
					// GA Trigger
					// /rated/episode
				}
			}
		}).send('id=' + this.options.id + '&r=' + a);
		this.set(a);
	},
	set: function(a) {
		this.stars.each(function(star, i) {
			if (i<this.options.rating) {
				star.set('class', 'staron');
			} else {
				star.set('class', 'star');
			}
		}, this);
	}
});