// cycle the headlines display by fading the active item and then moving it away so its links aren't active
var maxOpacity = 1.0;
function swapNews() {
	var active = $j('ul.headlines li.activeNews');
	var next = active.next();
	if (!next || next.length==0) {
		next = $j('ul.headlines li:first');
	} 
	hideHeadline(active);
	showHeadline(next);
	fixNewsForIE();
}

function showHeadline(headline) {
	headline.addClass('activeNews').animate({'top':0},10).animate({'opacity':maxOpacity},1000);
}

function hideHeadline(headline) {
	headline.removeClass('activeNews').animate({'opacity':0},1000).animate({'top':500},10);
}

function fixNewsForIE() {
  if($j.browser.msie){
  		// MSIE can't do opacity properly over a transparent PNG background
      $j('body#home div#body ul.headlines li.activeNews strong').css({ 'font-weight':'bold'});
  }	
}

// set up jQuery handlers
$j(document).ready(function() {

	// animate headlines on home page
	if ($j('body#home ul.headlines')) {
		$j('body#home ul.headlines').css('display','block');
		var count = Math.floor(Math.random()*$j('ul.headlines li').length);
		$j('ul.headlines li').animate({'opacity':0},10);
		showHeadline($j('ul.headlines li:eq(' + count + ')'));
		fixNewsForIE();
		setInterval("swapNews()", 6000);
	}
	
	// quick search for the search form
	if ($j('input.quicksearch')) {
		$j('input.quicksearch').quickSearch();
	}
	
	$j('.show-hidden').click(function() {
		$j(this).siblings().slideDown(400);
		$j(this).slideUp(400);
	});
	
	// Firefox doesn't smooth light text on black background, so make it fatter
	if ($j.browser.mozilla) {
		$j('div.footer p').addClass('fix-firefox-smoothing');
	}
	
	// end document ready function
});

