jQuery(document).ready(function(){
	$('body').addClass('json'); 
	sectionSelect();
	moveLinks();
});

function sectionSelect () {
	//set up required variables
	var reduced,
		subDt = jQuery('#section_selector dt'),
		defList = jQuery('#section_selector dl');
	
	// the css hides the dd's if the page has jq, this makes the first one visible
	$('#section_selector dd:eq(0)').css( 'display' , 'block' );
	$('#section_selector dt:eq(0)').css({ backgroundPosition : '0px -30px' });
	// Account for if there is less than Five Sub Sections in the list
	if (subDt.length == '4') {
		reduced = true;
	    defList.addClass('reduced');
	};

	//as ie6 can't css hover on a dd we give the client a pointer to show clickable
	$('#section_selector dt').hover(
		function() {
			$(this).css({ cursor : 'pointer' , 'background-position' : '0px -30px' });
		},
		function(){
			$(this).css({ cursor : 'normal' , 'background-position' : '0px 0px' });
		});
	
	// Now we need to put click handlers onto the dt's
	$("#section_selector dl dt").click( function() {
		var nextDD = $(this).next();
		if ( nextDD.is(':visible') ) {
			return false;
		}
		else {
			$( '#section_selector dd:visible(0)' ).slideUp( 400 , function() {
				if (reduced) {
					nextDD.slideDown(400).animate({ "height" : "118px" });					
				} else {
					nextDD.slideDown(400).animate({ "height" : "90px" });					
				};
				nextDD.prev().css({ backgroundPosition : '0px -30px' });					
			})
			.prev().css({ backgroundPosition : '0px 0px' });;
		};
	});
};

function moveLinks() {

	$('a.further').each(function() {
		var that = jQuery(this);
		that.appendTo(that.prev());
	});
};

