	
	function ratepostVote(post_id, vote) {
		jQuery.ajax({
			type: 'POST',
			data: {'post_id': post_id, 'vote': vote},
			url: 'http://allbetsareoff.com/wp/index.php?ak_action=ratepost_vote',
			timeout: 2000,
			error: function() {},
			success: function(r) { 
				ratepostVoteAvg(post_id);
			}
		})
		return false;
	}
	
	function ratepostVoteAvg(post_id) {
		jQuery.ajax({
			type: 'POST',
			data: {'post_id': post_id},
			url: 'http://allbetsareoff.com/wp/index.php?ak_action=ratepost_vote_avg',
			timeout: 2000,
			error: function() {},
			success: function(r) { 
				jQuery('#ratepost-'+post_id).find('div.rating-info').text('Rating ' + r + ' out of 5');
			}
		})
		return false;
	}
	
	jQuery(document).ready(function() {
		jQuery('div.ratepost').not('.voted').find('span div').hover(
			function() {
				rating_text = {
					'1': 'Needs Work',
					'2': 'Below Average',
					'3': 'Average',
					'4': 'Very Good',
					'5': 'Excellent'};
				$current = jQuery(this);
				$ratepost = $current.parent().parent();
				new_rating = $current.attr('rel');
				$ratepost.find('span').removeClass().addClass('rating' + new_rating);
				$ratepost.find('div.status-info').text(rating_text[new_rating]);
			},
			function (){
				$ratepost = jQuery(this).parent().parent();
				$ratepost.find('span').removeClass().addClass('rating' + $ratepost.attr('rel'));
				$ratepost.find('div.status-info').text('');
			});
		jQuery('div.ratepost').not('.voted').find('span div').click(function() {
			$current = jQuery(this);
			$ratepost = $current.parent().parent();
			vote = $current.attr('rel');
			post_id = $ratepost.attr('id').split('-')[1];
			$ratepost.find('span div').unbind();
			$ratepost.attr('rel', vote);
			$ratepost.find('span').removeClass().addClass('rating' + vote);
			$ratepost.find('div.status-info').text('Thank you for voting!');
			ratepostVote(post_id, vote);
		});
	});
