var TableHighlighting = {
	table_highlight: function(table, row_hover_class, column_hover_class, cell_hover_class){
//		if (typeof table == 'string')
//			table = $(table);
//		if (typeof table != 'object' || table.tagName != 'TABLE')
//			return;
		$(table).getChildren('tbody > tr').each(function(tr, trCount){
			//add the row class to the row
			//tr.addClass('row-' + trCount);
			//add the row listener
			if (row_hover_class){
				tr.addEvents({
					mouseenter: function(){
						tr.addClass(row_hover_class);
					},
					mouseleave: function(){
						tr.removeClass(row_hover_class);
					}
				});
			}
			//for every cell...
			if (column_hover_class || cell_hover_class){
				tr.getChildren('td:not(.no_highlight)').each(function(td, tdCount){
					//remember column and column items
					var column = 'col-' + tdCount;
					var friends = 'td.' + column;
					//add td's column class
					td.addClass(column);
					//add the cell and column event listeners
					td.addEvents({
						mouseenter: function(){
							if (column_hover_class)
								$$(friends).erase(td).addClass(column_hover_class);
							if (cell_hover_class)
								td.addClass(cell_hover_class);
						},
						mouseleave: function(){
							if (column_hover_class)
								$$(friends).erase(td).removeClass(column_hover_class);
							if (cell_hover_class)
								td.removeClass(cell_hover_class);
						}
					});
				});
			}
		});
	},
	
	init: function(){
		$$('table[class*=highlight]').each(function(table){
			var m = table.className.match(/\bhighlight\((.+)\)/);
			if (m){
				var para = m[1].split(',');
				TableHighlighting.table_highlight(table, para[0], para.length>1?para[1]:'', para.length>2?para[2]:'');
			}
		});
	}
}

window.addEvent('domready', TableHighlighting.init);

