var t;
var TimerOn = true;
var TimerLength = 0;

$(function(){
	if( $("body").hasClass('home') ){
		TimerLength = 5000;
		t=setTimeout("headlineRotation('btn-next')",1000);
	}else{
		TimerLength = 10000;
		t=setTimeout("headlineRotation('btn-next')",5000);
	}	
  
  $("#slideshow .navigation a").click(function(){
		var action = $(this).attr('class');
		headlineRotation(action);
		return false;
	})
  
	$("#showAllSummaries").click(function(){
		if($(this).html() == "Show All Summaries"){
			$(this).html('Hide All Summaries')
			$(".search-results dd .show-item").show();
		$(".search-results dd a.showSummary").html('Hide Summary');
		}else{
			$(this).html('Show All Summaries')
			$(".search-results dd .show-item").hide();
			$(".search-results dd a.showSummary").html('Show Summary');
		}
		return false;
	})
	
	$(".search-results dd a.showSummary").click(function(){
		if($(this).html() == "Show Summary"){
			$(this).html('Hide Summary')
		}else{
			$(this).html('Show Summary')
		}
		$(this).parent().parent().parent().find('.show-item').toggle();
		return false;
	})
  
});

function headlineRotation(action){
	var total = new Number;
	total = $("#slideshow .navigation span.total").html();
	var current = new Number;
	current = $("#slideshow .navigation span.current").html();
		
	if(action == "prev"){
		current--;
		if(current == 0){
			current = total;
		}
		$("#slideshow .navigation span.current").html(current);
	}else if(action == "next"){
		current++;
		if(current > total){
			current = 1;
		}
		$("#slideshow .navigation span.current").html(current);
	}else if(action == "stop"){
		$(".navigation .stop").hide();
		$(".navigation .play").show();
		TimerOn = false;
	}else if(action == "play"){
		$(".navigation .stop").show();
		$(".navigation .play").hide();
		TimerOn = true;
	}
	
	$(".slcontent").hide();
		$(".slphoto").hide();
		$("#slideshow .h"+current+"-photo").show();
		$("#slideshow .h"+current+"-content").show();
	
	if(TimerOn == true){
		clearTimeout(t)
		t=setTimeout("headlineRotation('next')",TimerLength);
	}else{
		clearTimeout(t)
	}
}
