
function ratepostVote(post_id, vote) {
	jQuery.ajax({
		type: 'POST',
		data: {'post_id': post_id, 'vote': vote},
		url: 'http://www.walkformissions.com/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://www.walkformissions.com/index.php?ak_action=ratepost_vote_avg',
		timeout: 2000,
		error: function() {},
		success: function(r) { 
			jQuery('#ratepost-'+post_id).find('div.Encouragement-info').text('Encouragement ' + r + ' out of 5');
		}
	})
	return false;
}

jQuery(document).ready(function() {
	jQuery('div.ratepost').not('.voted').find('span div').hover(
		function() {
			Encouragement_text = {
				'1': 'You can do it',
				'2': 'Give it all you got',
				'3': 'You are made of steel',
				'4': 'Run! Dont walk',
				'5': 'Olympics Material'};
			$current = jQuery(this);
			$ratepost = $current.parent().parent();
			new_Encouragement = $current.attr('rel');
			$ratepost.find('span').removeClass().addClass('Encouragement' + new_Encouragement);
			$ratepost.find('div.status-info').text(Encouragement_text[new_Encouragement]);
		},
		function (){
			$ratepost = jQuery(this).parent().parent();
			$ratepost.find('span').removeClass().addClass('Encouragement' + $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('Encouragement' + vote);
		$ratepost.find('div.status-info').text('Thank you for encouraging me!');
		ratepostVote(post_id, vote);
	});
});
