var CTableFlex = Class.create({
	idTable : '',
	atd     : new Array(),
	
	initialize : function(id) {
		this.idTable = id;
	},
	
	convert : function(w,h, table_class) {
		var t = $(this.idTable);

		if (t.hasClassName(table_class)) return;

		var atr = $A(t.childElements()[0].childElements());
		var atr_size = atr.size();
		
		var index = 0;

		for (i=0;i<atr_size;i++) {
			var atd = atr[i].childElements();
			var atd_size = atd.size();

			for (j=0;j<atd_size;j++) {
				if (!atd[j].empty()) {
					this.atd[index] = atd[j];
					index = index+1;
				}
			}
		}

		rows = Math.ceil(this.atd.size()/w);
		if (h && h<rows) rows = h;

		var tn = new Element('table');

		var tbody = new Element('tbody');
		tn.insert(tbody, 'bottom');
		
		for (hh=0;hh<rows;hh++) {
			var tr = new Element('tr');
			tbody.insert(tr, 'bottom');
			for (ww=0;ww<w;ww++) {
				index = hh*w+ww;
				
				if (this.atd[index]) {
					tr.insert(this.atd[index], 'bottom');
				} else {
					tr.insert(new Element('td'), 'bottom');
				}
			}
		}

		t.replace(tn);
		tn.addClassName(table_class).writeAttribute('id', 'flexTable');
	}
	
});
