$(document).ready(function() {
	
	var $headerRow = $('table#states-licensed thead tr');
	var $topRow = $('table#states-licensed tr.top-row');
	var $optionalRows = $('table#states-licensed tr').not($topRow).not($headerRow);
	var $stateTD = $('table#states-licensed td.state');
	
	var $topRowOptionalTD = $('table#states-licensed tr.top-row td').not($stateTD);	
	var $stateCheckBoxes = $('table#states-licensed td.state input');
	
	// initially hide optional checkboxes
	$topRowOptionalTD.addClass("collapsed");
	$optionalRows.hide();
	
	$stateCheckBoxes.click(function() {
		$thisCheckbox = $(this);
		$thisRowsOptionalTD = $($thisCheckbox).parent('td').siblings('td');	
		$thisOptionalRows = $($thisCheckbox).parent('td').parent('tr').siblings('tr');
		
		if ( this.checked )
		{
			$thisRowsOptionalTD.removeClass().addClass("expanded");
			$thisOptionalRows.fadeIn();
			// $thisOptionalRows.show();
		}
		else
		{
			$thisRowsOptionalTD.removeClass().addClass("collapsed");
			$thisOptionalRows.fadeOut();
			// $thisOptionalRows.hide();
		}


	});
	
});

