
/**
 * Call for each row of the data grid with tabs. It's called at each row so that giant
 * tables can start wiring together their tabs before the table is rendered completely.
 * Pass it the id prefix of the tab a tags and the tab content tbody tagss and the number
 * of tabs per row.
 */
function datagrid_tabs(tab_id, tbody_id, num) {
	var tabs = new Array();
	var tbodys = new Array();
	
	var current = -1;
	
	var close_tab = function(index) {
		rem(tabs[index].parentNode, 'open');
		add(tbodys[index], 'disHide');
	}
	
	var open_tab = function(index) {
		add(tabs[index].parentNode, 'open');
		rem(tbodys[index], 'disHide');
	}

	for(var i = 0; i < num; i++) {
		var tab = e(tab_id + i);
		var tbody = e(tbody_id + i);
		
		if(tab) {
			tabs[i] = tab;
			tbodys[i] = tbody;
			tab.i = i;
			tab.onclick = function() {
				this.blur();
				if(current != -1) {
					close_tab(current);
				}
				if(this.i == current) {
					current = -1;
				}
				else {
					open_tab(this.i);
					current = this.i;
				}
				return false;
			}
		}
	}
}