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

function qapromo_init() {
	//$('#QAPromo_content ul > li').css("display","none");
	qapromo_li_width = $('#QAPromo_content').width();
	$('#QAPromo_content ul').width($('#QAPromo_content ul > li').size() *qapromo_li_width);
	$('#QAPromo_bar_links ul > li a').click(function(){
		qapromo_switch(this.hash.replace(/#/, ''));
		return false;
	});
	qapromo_current = 0;
	qapromo_switch(1);
}

var qapromo_rotateTimeout;
function qapromo_switch(num) {
	if (num == undefined || num == "next") {
		if ((++qapromo_current) > $('#QAPromo_content ul > li').size()) { qapromo_current = 1; }
	} else if (num == "prev") {
		if ((--qapromo_current) < 1) { qapromo_current = $('#QAPromo_content ul > li').size(); }
	} else {
		qapromo_current = num;
	}
	num = qapromo_current;

	position = -1 * qapromo_li_width * (num - 1);

	$('#QAPromo_content ul').animate( { marginLeft: (position + "px")}, 600, "swing");
	$('#QAPromo_bar_links ul > li').removeClass('sel');
	$('#QAPromo_bar_link_'+num).addClass('sel');
	if (qapromo_rotateTimeout != undefined) clearTimeout(qapromo_rotateTimeout);
	qapromo_rotateTimeout = setTimeout('qapromo_switch()',8000);
}

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;
	});
}
