function init() {
	g_result=document.getElementById( g_table_id );
	if(g_result){
		g_tds=g_result.getElementsByTagName('td');
		window.onresize=resize;
		resize();
	}
}

function CountColumns() {
	var c = Math.floor( $( g_container ).width() / g_td_width );
	return c > 0 ? c : 1;
}
	
function resize() {
//	$( '#count' ).text( $( g_container ).width() );
	var cols=CountColumns();
	if(g_count==cols){return;}
//	alert('resize');
	g_count=cols; 
	var table=document.createElement('table');
	table.cellPadding=0;
	table.cellSpacing=0;
	var tbody=document.createElement('tbody');
	var rows=g_tds.length/cols;
	var width=100/cols;
	for(var j=0;j<rows;j++){
		var row1=document.createElement('tr');
		for(var i=0;i<cols;i++){
			if(!g_tds[0]){break;}
			g_tds[0].style.width=width+'%';
			row1.appendChild(g_tds[0]);
		}
		tbody.appendChild(row1);
	}
	table.appendChild(tbody);
	table=g_result.appendChild(table);
	var prev=table.previousSibling;
	if(prev!=null)prev.parentNode.removeChild(prev);
}
