$(document).ready(function(){

/*first we initialise by adding the 'all' checkbox unchecking the other boxes and adding the background class*/
//  only add top checkbox if JS is on
	addAllCheck();
	defaultSetting();
		
//when user clicks the reset button all the checkboxes get unchecked
	 $("input[type='reset']").click(function() {
		defaultSetting();
		return false;
	})		
		
//when user clicks the top checkbox all the other checkboxes in the list get unchecked
	$('.form_console li:first-child :checkbox').click(function() {
		if (this.checked) {	 
			$(this).parent().siblings().removeClass("hilite");
			$(this).parent().siblings().children().attr('checked', '');
			}
	})
	
//when the user clicks on a box the colour changes and the top box gets unchecked if applicable
	$('li:not(li:first-child) :checkbox').click(function() {
		if (this.checked) {
			$(this).parent().siblings("li:first-child").removeClass("hilite");
			$(this).parent().siblings("li:first-child").children().attr('checked', '');
		}	
	})		
		
//toggle the highlighting when checkboxes clicked
	$('li :checkbox').click(function() {
		if (this.checked) {
			$(this).parent("li").addClass("hilite");
		}
		else{
			$(this).parent("li").removeClass("hilite");
		}
	}); 		
}); 

//checks every checkbox except one. Used when someone presses the 'all' checkbox or reset button
function defaultSetting(){
	 $('li :checkbox').removeAttr('checked');
	 $('li :checkbox').parents("li").removeClass("hilite");
	 $('li:first-child :checkbox').attr('checked', 'true');
	 $('.form_console li:first-child').addClass("hilite"); 
	}

//adds the top check box on-the-fly for the benefit of non-javaScript users
function addAllCheck(){
	var strAppended = '<li class="extraInfoHover bevel"><input type="checkbox" id="entry_type0" name="filter" value="entry_type/All_vacancies" class="hoverFocus" checked><label for="entry_type0">All</label></li>';
	$("#jobOptions").prepend(strAppended);
	}