$(function() {
	$('.slide_show').cycle({
	    fx: 'fade',
	    timeout: 5000,
	    pauseOnPagerHover: true,
	    prev: '.prev',
	    next: '.next'
	});

	$('.featured_photo .caption').hide();

	$('.featured_photo').hover(
		function(){
			$(this).css('position', 'relative');
			caption_div = $(this).find('.caption');

			padding = parseInt(caption_div.css('padding-top')) + parseInt(caption_div.css('padding-bottom'));
			height = $(this).find('img').height();
			top = parseInt(height/2);

			caption_div.css('position', 'absolute')
				.css('top', top)
				.height((height - top - padding))
				.fadeIn();
		}
		,function() {
			caption_div = $(this).find('.caption').fadeOut();
		}
	);

	$('.publications_nav').show();

	$('.publications_nav .prev_btn').click(function(e){
		e.preventDefault();

		current = $('.supplemental .publications:visible');
		previous = current.prev('div.publications');

		if (previous.length == 0) {
			return // Already showing the first publication
		}

		current.hide();
		previous.fadeIn();

		$('.publications_nav .next_btn').find('img').removeClass('inactive');

		// If this is first, make the prev button inactive.
		check = previous.prev('div.publications');

		if (check.length == 0) {
			$(this).find('img').addClass('inactive');
		}

	});
	$('.publications_nav .next_btn').click(function(e){
		e.preventDefault();

		current = $('.supplemental .publications:visible');
		nextPub = current.next('div.publications');

		if (nextPub.length == 0) {
			return // Already showing the last publication
		}

		current.hide();
		nextPub.fadeIn();

		$('.publications_nav .prev_btn').find('img').removeClass('inactive');

		// If this is last, make the next button inactive.
		check = nextPub.next('div.publications');

		if (check.length == 0) {
			$(this).find('img').addClass('inactive');
		}
	});
});

