var t=setTimeout("headlineRotation('btn-next')",5000);
var TimerOn = true;

$(function(){
	
	$(".homepage .hl-controls li a").click(function(){
		var action = $(this).attr('class');
		headlineRotation(action);
		return false;
	})
	
	$(".region h3 a.minimize").click(function(){
		$(this).parent().parent().find(".program").toggle();
		$(this).toggleClass('maximize');
		return false;
	})
  
	$(".chart-header a.collapse").click(function(){
		$(this).parent().parent().toggleClass('collapsed');
		return false;
	})
	
	$("ul#ajax-toggle li a").click(function(){
		var target = $(this).attr('href');
		$("#ajax-content .fragment").hide();
		$("#ajax-content "+target).show();
		$("ul#ajax-toggle li").removeClass('active');
		$(this).parent().addClass('active');
		return false;
	})
	
	$("#col-1 .nested > li > a").click(function(){
		$(this).parent().find("ul").toggle();
		return false;
	})
	
	$(".results-filters #show-filters").click(function(){
		filterForm('show');
		return false;
	})
	
});

function columnSizeAdjust(){
	$(".chart").each(function(){
		var numSchools = $(this).find("th.school").length;
		if(numSchools == 2){
			$(this).find('th.school a').hide();
		}
		var schoolWidth = Math.round(435/numSchools-6);
		$(this).find(".school").css('width',schoolWidth + 'px');
	})
}

function filterForm(action){
	$.ajax({
		url: '/_ajax_remember_filter_display.cfm?subfilter='+action,
		success: function(data){}
	})
	if(action == 'show'){
		$("#program-advanced-filter").show();
		$(".results-filters #show-filters").hide();
	}else{
		$("#program-advanced-filter").hide();
		$(".results-filters #show-filters").show();
	}
}

function headlineRotation(action){
	var total = new Number;
	total = $("body.homepage .hl-controls span.total").html();
	var current = new Number;
	current = $("body.homepage .hl-controls span.current").html();
		
	if(action == "btn-prev"){
		current--;
		if(current == 0){
			current = total;
		}
		$("body.homepage .hl-controls span.current").html(current);
	}else if(action == "btn-next"){
		current++;
		if(current > total){
			current = 1;
		}
		$("body.homepage .hl-controls span.current").html(current);
	}else if(action == "btn-stop"){
		$(".btn-stop").css('display','none');
		$(".btn-play").css('display','block');
		TimerOn = false;
	}else if(action == "btn-play"){
		$(".btn-stop").css('display','block');
		$(".btn-play").css('display','none');	
		TimerOn = true;
	}
	
	$(".hl-text").hide();
	$(".hl-img").hide();
	$(".headline-rotator .image"+current).show();
	$(".headline-rotator .content"+current).show();
	
	if(TimerOn == true){
		clearTimeout(t)
		t=setTimeout("headlineRotation('btn-next')",5000);
	}else{
		clearTimeout(t)
	}
}
