jQuery.fn.gridtable = function () {
	
	
	jQuery(this).each(function () {
		if(jQuery(this).hasClass('disable')) {
			return;
		}
		var table = jQuery(this);
		table.find('.th-inner-text, .td-inner-text').hide();
//		table.find('table.gridtable .th-inner-text, table.gridtable .td-inner-text').hide();
	
		
		table.find('th').not(':first-child').mouseenter(function () {
			jQuery(this).addClass('selected');
			var index = table.find('th').index(this);
			
			table.find('tr').each(function () {
				jQuery(this).find('td').eq(index).addClass('selected');
			});
			
		});
		
		table.find('tr td:first-child').mouseenter(function () {
			jQuery(this).parents('tr').find('td').addClass('selected');
		});
		
		table.find('tr td').not(':first-child').mouseenter(function () {
			var column = table.find('tr');
			var row = jQuery(this).parents('tr').find('td');
			var rowIndex = row.index(this);
			var columnIndex = column.index(jQuery(this).parent());
	
			
			for(var n=rowIndex; n>=0; n--) {
				row.eq(n).addClass('selected');
			}
	
			for(var n=columnIndex; n>=0; n--) {
				column.eq(n).find('td, th').eq(rowIndex).addClass('selected');
			}
		});
	
		table.find('th, td').mouseleave(function () {
			table.find('.selected').removeClass('selected');	
		});
	});
	return this;
};

jQuery(document).ready(function () {

	jQuery('table.gridtable').gridtable();	
	
});
