// Hightlight table rows
var tableHighlighter = new Class({	
	
	options: {
			rowColourClass: 'highlighted',
			rowHoverColourClass: 'hoverHighlighted',
			highlightRow: 'odd',
			everyOther: 0,
			link: false
	},
	
	initialize: function( id, options ) {
		this.setOptions( options );
		if( this.options.highlightRow == 'odd' ){
			this.options.everyOther = 1;
		}
		this.rows = $(id).getElements('tbody tr');
		this.rowsLength = this.rows.length;
		this.addHighlighting();
		if( this.options.link == true )
			this.addLinks();
	},
	
	addHighlighting: function(){
		var hoverClass = this.options.rowHoverColourClass;
		for( var i = 0; i < this.rowsLength; i++ ){
			$( this.rows[i] ).addEvents({
				'mouseover': function(){ this.addClass( hoverClass ); },
				'focus': function(){ this.addClass( hoverClass ); },
				'mouseout': function(){ this.removeClass( hoverClass ); },
				'blur': function(){ this.removeClass( hoverClass ); }
			});
			if( this.options.everyOther != 0 ){
				this.rows[i].addClass( this.options.rowColourClass );
				this.options.everyOther = -1;
			}
			this.options.everyOther++;
		}
	},
	
	addLinks: function(){
		for( var i = 0; i < this.rowsLength; i++ ){
			$( this.rows[i] ).addEvent('click', function() { location.href = this.get('rel'); });
		}
	}
});

tableHighlighter.implement(new Options);
