$.fn.checkboxtable = function() {
	return this.each(function() {
		
		var table = $(this);
		
		table.find('tr:has(input[type=checkbox])').each(function(){
			// pro kazdy TR obsahujici checkbox
			var tr = $(this);
			// najdi TD, ktere neobsahuje checkbox
			tr.find('td:not(:has(input[type=checkbox]))')
		   .click(function() {  // na kliknuti na TD
			   // odskrtni vsechny
			   table.find('input[type=checkbox]:checked').removeAttr('checked'); 
			   // vezmi z TR checkbox a zaskrtni ho
			   var checkbox = tr.find('input[type=checkbox]:first');
			   checkbox.attr('checked', !checkbox.is(':checked'));
		   });	   
		})
		// pro TR men barvu pri najeti mysi
		.mouseover(function() {			
		   $(this).addClass('selected');
		})
		.mouseout(function() {			
		   $(this).removeClass('selected');
		});
		
		// check all
		$(this).find('th.checkAll:first').click(function() {			
			var checkedAll = $(this).attr('checkedall') == 'true' ? true : false;
			
			// obratime hodnotu - pokud bylo zaskrtnuto, je odskrtnuto atd
			$(this).attr('checkedall', checkedAll ? false : true);
			
			table.find('input[type=checkbox]').each(function() {
				$(this).attr('checked', !checkedAll);
			});			
		});
	});
};