$(document).ready(function(){
	if ($('ul.lifestream-full li').length > 1) {
		$('ul.lifestream').addClass('js').append('<li class="overlay-fade" /><li class="overlay" />');
		$('ul.lifestream-full').after('<ul class="lifestream lifestream-links" />');
		$('ul.lifestream-full li.lifestream').each(function() {
      var id = $(this).index() + 1;
      $(this).attr('id', 'news-summary_' + id);
      if (!$(this).hasClass('overlay') && !$('#news-link_' + id).length) {
        $('.lifestream-links').append('<li class="lifestream" id="news-link_' + id + '"><div class="date more">' + $(this).children('.date').html() + '</div><div class="title">' + $(this).children('.title').html() + '</div></li>');
        $('#news-link_' + id).attr("style", $(this).attr("style"));
      }
		});
    var which = $('ul.lifestream-full li.lifestream:first').attr('id').replace(/^news-summary_/, "");
    featuredNav(which);
		var scr = setInterval(featuredScroll, 5000);
		$('div.lifestream').bind('mouseenter', function() {
			clearInterval(scr);
		}).bind('mouseleave', function() {
      clearInterval(scr);
			scr = setInterval(featuredScroll, 5000);
		});
	}
	$('ul.lifestream li.lifestream:first').addClass('selected');

	$('ul.lifestream-links li.lifestream').hover(function() {
		var id = $(this).attr('id').replace(/^news-link_/, "");
		if (!$(this).hasClass('selected')) {
			featuredNav(id);
		}
	});
	function featuredNav(which, speed) {
		if (speed) {
			$('ul.lifestream-full .overlay').fadeIn(speed, 'easeInOutQuad', function() {
				$('div.lifestream .selected').removeClass('selected');
				$('#news-summary_' + which + ', #news-link_' + which).addClass('selected');
				$(this).fadeOut(speed, 'easeInOutQuad');
			});
		} else {
			$('div.lifestream .selected').removeClass('selected');
			$('#news-summary_' + which + ', #news-link_' + which).addClass('selected');
		}
	}
	function featuredScroll() {
		if($('ul.lifestream-full .selected').next().length && !$('ul.lifestream-full .selected').next().hasClass('overlay-fade')) {
			var which = $('ul.lifestream-full .selected').next().attr('id').replace(/^news-summary_/, "");
		} else {
			var which = $('ul.lifestream-full li.lifestream:first').attr('id').replace(/^news-summary_/, "");
		}
		featuredNav(which, 600);
	}
});
