$(function(){
	table();
});

function table(){
	$('tr', '#sample-table')
	.hover(
		function(){
			$(this).addClass('tr-selected');
		},
		function(){
			if(!$('input[type="checkbox"]', this).attr('checked')){
				$(this).removeClass('tr-selected');
			}
		}
	);
	$('tr:odd', '#sample-table')
	.addClass('tr-odd');
	$('#chkAll')
	.toggle(
		function(){
			$('input[type="checkbox"]', '#sample-table')
			.attr('checked', true);
			$(this)
			.html('Uncheck All');
			$('tr', '#sample-table')
			.addClass('tr-selected');				
		},
		function(){
			$('input[type="checkbox"]', '#sample-table')
			.attr('checked', false);
			$(this)
			.html('Check All');
			$('tr', '#sample-table')
			.removeClass('tr-selected');				
		}
	);
	$('tr', '#sample-table')
	.children('td:nth-child(1)')
	.nextAll()
	.click(
		function(){
			var _e = $('input[type="checkbox"][name^="chk"]', $(this).parent().children('td:first'));
			if(_e.attr('checked')){
				_e.attr('checked', false);
				$(this).parent().removeClass('tr-selected');
			}else{
				_e.attr('checked', true);
				$(this).parent().addClass('tr-selected');
			}
		}
	);
}
