/*var jsPath			= ""; 	



var partsIncluded 	= false;
function includeJS( file )
{
		document.getElementsByTagName('head')[0].appendChild( 
					$('<script></script>')
					.attr( "type", "text/javascript")
					.attr( "src", jsPath + file )
					.get(0)
		);
}


includeJS( "table.filters.js" );


if( !partsIncluded ) 	alert( "invalid path" );
*/





var Table = function( jsonString ) {
	this.construct( jsonString );
};

Table.prototype.options 	= {};
Table.prototype.table		= null;
Table.prototype.hasFilters 	= true;
Table.prototype.nrColumns	= 0;

Table.prototype.construct = function ( jsonString )
{
	this.options 	= $.parseJSON( jsonString );
	
	this.table 		= $('<table></table>').attr( "id", "listTableCMS" );
	$( '#listTableContainer' ).append( this.table );
	
	this.nrColumns = this.options.columns.length;
	
	this.buildFilters();
	this.buildRows();
};

Table.prototype.buildFilters = function ()
{
	var tr = $( '<tr></tr>' );
	
	for( i=0; i < this.nrColumns; i++ )
	{
		var column = this.options.columns[i];
		
		if( column.filter.type != "none" )
		{
			this.hasFilters = true;
		}
		
		tr.append( this.buildFilter( column.filter ) );
	}
	
	if( this.hasFilters ) this.table.append( tr );
};

Table.prototype.buildRows = function ()
{
	var thisObj = this;
	$.getJSON( 
			this.options.dataProvider.url, 
			this.options.dataProvider.callVars, 
			function( data )
			{
				thisObj.onRowsReceived( data, thisObj ); 
			}
	);
};


Table.prototype.onRowsReceived = function( data, thisObj )
{
	for( k=0; k < data.rows.length; k++ )
	{
		thisObj.table.append( thisObj.buildRow( data.rows[k] ) );
	}
};

