function highlightStory(teaser) {
	$('div.story.highlight > .full-story').stop().css({'opacity': 1}).animate({opacity: 0}, 750, 'swing', 
			function () { 
				$(this).parent().removeClass('highlight'); 
				$(teaser).parent().addClass('highlight').find(".full-story").stop().css({'opacity': 0}).animate({opacity: 1}, 1500, 'swing');
			});
}

var highlightTimeout = null;
var autoAdvancer = null;

$(document).ready( 
	function () {
			$('.short-story').click( function (event) { 
										if(event.target == this) {
											clearTimeout(highlightTimeout);
											highlightStory( this ); 
										}
									 } );
			$('.short-story').hover( function (event) { 
										if(event.target == this) {
											resetAutoAdvancer();
											clearTimeout(highlightTimeout);
											var obj = this; 
											highlightTimeout = setTimeout(function () { highlightStory(obj); }, 1000); 
										}
									},
									 function () { }
									);
			
			resetAutoAdvancer();
	});
	
function resetAutoAdvancer() {
	if(autoAdvancer) {
		clearInterval(autoAdvancer);
		//$('#debug').html('reset auto-advancer ' + autoAdvancer);
	}
	autoAdvancer = setInterval( function () { 
							//$('#debug').html('apel auto-advancer ' + autoAdvancer);
							var next = $('div.story.highlight').next();
							if(next.size() == 0 || next.hasClass('border'))
								next = $('div.story');
							highlightStory( next.find(".short-story")[0] ); 
						}, 10000);
}
