AWP.Layer.Grid = function(config) {
	var tab = config.tab;
	var layer = config.layer;
	var store = config.store;
	
	config.columns = config.columns || AWP.cfg.DEFAULT_COLUMNS;
	
	var autoExpandColumn = '';
	for (var i = 0, len = config.columns.length; i < len; i++) {
		if (config.columns[i].autoExpand === true) {
			autoExpandColumn = config.columns[i].id;
			break;
		}
	}
	
	config = Ext.apply(config, {
		el: tab.body.id,
		store: store,
		/**
		 * Outr TabPanel with border and inner GridPanel without border are better
		 */
		border: false,
		trackMouseOver: false,
		enableHdMenu: false,
		enableColumnMove: false,
		disableSelection: false,
		loadMask: true,
		
		autoExpandMin: 200,
		autoExpandColumn: autoExpandColumn
	});
	
	config.viewConfig = {
		forceFit: false,
		autoFill: false,
		getRowClass : function(record, rowIndex, p, store){
			return 'x-grid3-row-collapsed';
		}
	};
	
	config.bbar = new Ext.PagingToolbar({
		pageSize: 10,
		store: store,
		displayInfo: true,
		displayMsg: 'Selected features {0} - {1} of {2}',
		emptyMsg: "No selected features",
		
		items:[{
				text: '',
				iconCls: 'awp-showall',
				//enableToggle: true,
				handler: layer.showAllFeatures.createDelegate(layer)
			}, '-', layer.layerId == 'helen_edit' ? '<input id="water-kw" type="text" />' : '-',
			layer.layerId == 'helen_edit' ? {
				text: '<b>Try</b> searching by Keyword...',
				tooltip: "Some information applies over to large an area to be searched for spatially."
					+ " If you didn't find what you are looking for try searching by Keyword.",
				handler: function() {
					var kw = document.getElementById('water-kw').value;
					AWP.map.getControlsByClass('AWP.Control.Search')[0].searchByKeywords(kw);
				}
			} : '-'
		],
		listeners: {
			beforechange: function(toolbar, params) {
				params.ps = Math.ceil((params.start + toolbar.pageSize) / toolbar.pageSize);
				params.pl = toolbar.pageSize;
				
				layer.beforeRefresh();
			}
		}
	});
	
/*	config.bbar.addButton({
		tooltip: 'Show All Features',
		//iconCls: "x-tbar-page-first",
		disabled: false,
		handler: this.showAllFeatures.createDelegate(this)
	});*/
	
	AWP.Layer.Grid.superclass.constructor.call(this, config);
	
	var sm = this.getSelectionModel();
	sm.addListener('rowselect', layer.onRowSelect, layer);
	sm.addListener('rowdeselect', layer.onRowDeselect, layer);
	
	tab.ownerCt.addListener('bodyresize', this.adjustHeight, this);
}

Ext.extend(AWP.Layer.Grid, Ext.grid.GridPanel, {
	adjustHeight: function(tabPanel) {
		this.setHeight(tabPanel.getInnerHeight());
	},
	showAllFeatures: function() {
		alert('bb')
	}
});
