$(function() {
	$('form.vote').live('submit', function() {	
		var url = 'http://www.myhorriblesecret.com/wp-content/themes/horrible-theme/lib/';
			post_id = $(this).find('input.vote_post_id').attr('value');
		 	count = $(this).find('input.vote_count').attr('value');
			ip = $(this).find('input.vote_ip').attr('value'); 	 
			form_id = $(this).attr('id');
			cast_vote = 'post_id=' + post_id + '&count=' + count + '&ip=' + ip;
			original_count = $(this).find('span.votes_count b').html();
			new_value = parseInt(original_count) + 1;
	  	$.ajax({
	    	type: 'POST',
	    	url: url + 'cast.php',
			cache: false,
			timeout: 10000,
	    	data: cast_vote,
			success: function(data) {
				$('form#' + form_id).find('span.votes_count').css('display', 'none');	
				$('form#' + form_id).addClass('user_voted disabled');
			},
			complete: function() {
				$('form#' + form_id).find('span.votes_count').fadeIn(3000, function() {
					if(new_value == 1) {
						$(this).html('<b>' + new_value + '</b>' + ' vote');
					} else {
						$(this).html('<b>' + new_value + '</b>' + ' votes');
					}
				});	
				$('form#' + form_id).find('input.vote_up').removeClass('vote_up').addClass('voted').attr('disabled', 'disabled');
			}
	  	});
		return false; 
	});
});
