function show_featured(tab) {
  
	switch(tab)
	{
	case 'tab1':
	  story = 'one';
	  break;    
	case 'tab2':
	  story = 'two';
	  break;
	case 'tab3':
	  story = 'three';
	  break;
	}
		
	$("#divHeader div.featured_story. "+story+" .story_copy").fadeIn("slow");
	$("#divHeader div:not(."+story+") .story_copy").fadeOut("slow"); // Get rid of all div that don't have our class

	$("#divHeader div."+story+" img").fadeIn("slow");
	$("#divHeader div:not(."+story+") img").fadeOut("slow"); // Get rid of all img that don't have our class
	if(tab) { 
		$("#featured_story_selector li#"+tab+" div").slideDown("fast"); // Open the tab we are mousing over
		$("#featured_story_selector li:not(#"+tab+") div").slideUp("fast");// If not id of the tab we are on then close them.
	}		
}

function show_next_featured() {		
  		
	// Find out which tab is open by checking to see if the child div of li is NOT hidden
    tabOpen = $("#featured_story_selector li div:not(:hidden)").parent().attr("id");
	switch(tabOpen)
	{
	case 'tab1':
	  tab = 'tab2';
	  break;    
	case 'tab2':
	  tab = 'tab3';
	  break;
	case 'tab3':
	  tab = 'tab1';
	  break;
	}
	show_featured(tab);
							
}


$(document).ready(function() {
						   
		$("#featured_story_selector li#tab1 div").slideDown("fast");
		
		$("#featured_story_selector li a").mouseover(function(){	  
				tab = $(this).parent().attr("id");
				show_featured(tab);
				// Remove the timer if we mouse over so it doesn't switch to a new tab while the user is reading.
				clearTimeout ( intID );
		});
		
		$("#featured_story_selector li a").mouseout(function(){
				// Start it up again now we have moved off the tab.
				intID = setInterval(function() {
						show_next_featured();
				}, 6000);											  
		});
		
		if($("#featured_story_selector").length > 0) {
			// Set the featured to change every nth second
			intID = setInterval(function() {
					show_next_featured();
			}, 6000);
		}
});


