
new Asset.css('style/zebratable.css');

var ZebraTable = new Class(
{
	Extends: Table,

	/*
	 * Constructor for this class
	 *
	 * @param string id
	 * @param Object options
	 */
	initialize: function (id, options)
	{
		this.setOptions(options);
		this.parent(id, options);
		this.table.addClass('ZebraTable');

		this.render();
	},

	/*
	 * This function renders the zebra style layout for the table
	 */
	render: function ()
	{
		if (this.countRows() == 0)
			return;

		// Add class to the odd rows
		this.tableBody.getElements('tr:odd').each(function (item, index)
		{
			item.addClass("odd");
		});
		// Add class to the even rows
		this.tableBody.getElements('tr:even').each(function (item, index)
		{
			item.addClass("even");
		});
		
		// Add event listeners to all rows
		this.tableBody.getElements('tr').each(function (item, index)
		{
			item.addEvents(
			{
				'mouseover': function (event)
				{
					this.addClass('hover');
				},
				'mouseout': function (event)
				{
					this.removeClass('hover');
				}
			});
		});
	},
	
	clear: function ()
	{
		this.tableBody.getElements('tr').each(function (item)
		{
			item.removeClass('odd');
			item.removeClass('even');
			item.removeEvents('mouseover');
			item.removeEvents('mouseout');
		});
	},
	
	refresh: function ()
	{
		this.clear();
		this.render();
	}
});
