$(document).ready(function() {
	
	//count and display number of hotlist links. also reveal the first one.
	var hotlist_links = 0;
	var revealed_one = false;
	$('#hotlist a').each(function() {
		if (!revealed_one) {
			$(this).css('display', 'inline');
			revealed_one = true;
		}
		++hotlist_links;
	});
	
	$('#hotlist_count').html(hotlist_links);



	$('.hotlist_ctrl').click(
		function() {
			navHotlist($(this));
		}
	);
	
	
})



function navHotlist(link) {
	var action = 'next';
	var link_id = link.attr('id');
	var link_action = link_id
	link_action = link_action.replace(/^hotlist_ctrl_/, '');
	action = link_action;
	
	//loop through hotlinks. save next, current, and prev
	var last_link = false;
	var prev_link = false;
	var current_link = false;
	var next_link = false;
	
	$('#hotlist a').each(function() {
		if ($(this).css('display') != 'none') {
			current_link = $(this);
			prev_link = last_link;
		}
		
		else if (current_link) {
			next_link = $(this);
		}
		
		last_link = current_link;
	});
	
	var byebye = current_link;
	var gobyebye = false;
	var hello = false;
	
	if (action == 'prev' && prev_link) {
		gobyebye = true;
		hello = prev_link;
	}
	
	else if (action == 'next' && next_link) {
		gobyebye = true;
		hello = next_link;
	}
	
	if (gobyebye) {
		byebye.fadeOut(
			400,
			function() {
				hello.fadeIn();	
			}
		);
	}
}
