function topnews_init() {
	$('.topnewscontent').each(function(){
		$(this).bind("mouseenter", function(){
			$(this).addClass('topnewscontent_hover')		
		}).bind("mouseleave",function(){
			$(this).removeClass('topnewscontent_hover')		
		});
	});
}

function likebutton_save(id, direction) {
	var re = RegExp('^vote_([a-z]+)_(\\d+)$');
	var match = re.exec(id);
	var object_type = match[1];
	var object_id = match[2];

	$.post('/' + object_type + '/' + object_id + '/vote/' + direction + '/', function(data) {
		// null
	});
}

function likebutton_init() {
	$('.likebutton_up').click(function(){
		if ($(this).parent().hasClass('likebutton_like')) {
			$(this).parent().removeClass('likebutton_like');
			$(this).next().fadeOut("fast", function(){$(this).text("Vote").fadeIn("fast")});
			likebutton_save($(this).parent().get(0).id, 'clear');
			return false;
		}
		if ($(this).parent().hasClass('likebutton_dontlike')) {
			$(this).parent().removeClass('likebutton_dontlike');
		}
		$(this).parent().addClass('likebutton_like');
		$(this).next().fadeOut("fast", function(){$(this).text("Up").fadeIn("fast")});
		likebutton_save($(this).parent().get(0).id, 'up');
		return false;
	});
	$('.likebutton_down').click(function(){
		if ($(this).parent().hasClass('likebutton_dontlike')) {
			$(this).parent().removeClass('likebutton_dontlike');
			$(this).prev().fadeOut("fast", function(){$(this).text("Vote").fadeIn("fast")});
			likebutton_save($(this).parent().get(0).id, 'clear');
			return false;
		}
		if ($(this).parent().hasClass('likebutton_like')) {
			$(this).parent().removeClass('likebutton_like');
		}
		$(this).parent().addClass('likebutton_dontlike');
		$(this).prev().fadeOut("fast", function(){$(this).text("Down").fadeIn("fast")});
		likebutton_save($(this).parent().get(0).id, 'down');
		return false;
	});
}

