/////////////////////////
// TABLES
/////////////////////////
$(function(){
  // Таблици - слага клас на първи и последен чайлд
  $('table.standard td:first-child, table.standard th:first-child').addClass('first');
  $('table.standard td:last-child, table.standard th:last-child, table.standard tr:last-child').addClass('last');
  $('table.standard tr:last-child').addClass('last');
});


/////////////////////////
// COLLAPSIBLE TABLES
/////////////////////////
$(function(){
	initTable();	
});

function initTable()
{
	$('table tr:last-child').addClass('last');
	var cSpan = $('table tbody:first tr:first-child').children().size();
	
	$('tbody .switch').closest('tr').addClass('clickable');

	$('tbody .switch').closest('tr').click(function(ev) {
		ev.preventDefault();
		$(this).closest('tbody').toggleClass('closed');
	});
	
	$('.collapsible .switch').not(':first').closest('tbody').addClass('closed').append('<tr class="vSpace"><td colspan="'+cSpan+'"></td></tr>');
	
	$('tbody:not(.closed) .switch').closest('tr').toggle(function() {
			$(this).closest('tbody').append('<tr class="vSpace"><td colspan="'+cSpan+'"></td></tr>');
		},function() {
			$(this).closest('tbody').children('.vSpace').remove();
	});
	$('tbody.closed .switch').closest('tr').toggle(function() {
			$(this).closest('tbody').children('.vSpace').remove();
		},function() {
			$(this).closest('tbody').append('<tr class="vSpace"><td colspan="'+cSpan+'"></td></tr>');
	});	
}
