window.addEvent('domready', function() {
	
	function submit_vote(hash, rid, vote)
	{
		new Ajax(base_url + 'proxy/submit_vote/' + hash + '/' + rid + '/' + vote, {
			method: 'post',
			onComplete: function(r) {
				if(r != '')
				{
					if(vote == 'up') {
						$$('#review' + rid + ' .thumbs .thumb_up').setText(r);
					} else {
						$$('#review' + rid + ' .thumbs .thumb_down').setText(r);
					}
				}
			}
		}).request();
	}

	$$('.review_posts').each(function(post) {

		var id = post.getProperty('id');
		
		$$('#' + id + ' .entry_wrap .thumbs a').each(function(a) {
			a.addEvent('click', function(e){

				e = new Event(e).stop();

				var string	= $$('#' + id + ' .thumbs span').getText();
					string	= new String(string).split('|', 2);
				var hash	= string[0];
				var rid		= string[1];

				if(a.hasClass('thumb_up')) {
					submit_vote(hash, rid, 'up');
				} else if(a.hasClass('thumb_down')) {
					submit_vote(hash, rid, 'down');
				}
			});
		});
	});
	
});
