
$(document).ready(function() {

	// when document is ready, hide all subsectors
	$(".checkboxExpertise").each( function() {
		getSectorblockFromCheckbox(this).hide();
	});
	
	
	// when clicked, toggle display
	$(".checkboxExpertise").click( function() {
	
		$block = getSectorblockFromCheckbox(this);
		
		// if visible, hide it and uncheck all sub choices		
		// if not visible, display it
		if ( $block.is(":visible") ) {
		
			// uncheck all
			$block.find("[type=checkbox]").each( function() {
				$(this).removeAttr("checked");
			});
			
			// then hide the block
			$block.slideUp();
			
		} else {
			// display it
			$block.slideDown();
			
		}
		
	});
	

});

function getSectorblockFromCheckbox($checkbox_o) {

	$sectorBlock_s = $checkbox_o.id;
	$sectorBlock_s = $sectorBlock_s.replace("checkbox", "sectorOf");
	
	// return a jquery object
	return $("#" + $sectorBlock_s );
}

