(function($) {
	$.fn.easygrid = function(options) {
		var defaults = {
			alternateBackground: true,
			allowRowSelect: true
		};

		options = $.extend(defaults, options);

		return this.each(function(index, table) {
			setAlternateBackground($('tr:odd td', table), options.alternateBackground);
			rowSelection(table, options.allowRowSelect, options.alternateBackground);
		});
	};

	function setAlternateBackground(rows, alt) {
		if(alt == true) {
			rows.attr('class', this.className + ' alt');
		}
	}
	
	function rowSelection(table, allowSelect, alt) {
		if(allowSelect == true) {
			$('tr', table).click(function() {
				//reset all rows
				$('tr', table).each(function() {
					$('td', this).each(function(index, cell) {
						$(cell).attr('class', cell.className.replace(' selected'));
					});
				});

				//restore alt backgrounds
				setAlternateBackground($('tr:odd td', table), alt);

				//select this row
				$('td', this).attr('class', this.className + ' selected');
			});
		}
	}
})(jQuery)