// Closures are good - always use 'em! 
//   (they localise state removing the global overwrite problem :))
(function($) {
	$(document).ready(function() {
		setupAccordions();
	});
	
	function setupAccordions()
	{
		/*
			Adapted from the jQuery blog.
		*/
		
		// itterate through each instance of the accordion
		$('dl.kentAccordion').each(function(index) {		
			var context = $(this);

			// hide all accordion areas except the first
			$('dd:not(:first)', context).hide();
			
			// set first one to active
			$('dt:first a', context).addClass('active');
			
			// when a heading is clicked (focused - device independant) hide all visible and open the appropriate area
			$('dt a', context).focus(function() {
				// check we are not already open
				if ($(this).attr('class') == 'active') {
					return false;
				}
				
				$('dt a', context).removeClass('active');
				$(this).addClass('active');
				
				$('dd:visible', context).slideUp('fast');
				$(this).parent().next().slideDown('fast');
				return false;
			});
			
			$('dt a', context).click(function() {
				// safari doesn't seem to think click is focus so we route the event
				$(this).focus(); 
				
				// stop the default action (following a href).
				return false;
			});
		
		});
	}

})(jQuery);