(function(){

this.RowClick = new Class({
	
	Implements: Options,
	
	options: {
		'target': 'tbody.rowclick tr',
		'relay': 'td',
		'classname': 'rowclick-over',
		'rel': 'rowclick',
		'check': false
	},
	
	initialize: function(options){
		this.setOptions(options);
		this.elements = $$(this.options.target);
		var self = this;
		var events = ['click', 'mouseover', 'mouseout'].each(function(name){
			self['_'+name] = name+':relay('+self.options.relay+')';
		});
		this.elements.addEvent(this._click, function(event){
			if (self.options.check && $check.call(this)) return false;
			var parent = this.getParent();
			var newLocation = (parent.getElement('[rel='+self.options.rel+']') || parent.getElement('a')).get('href');
			location.href = newLocation;
			event.stop();
		});
		this.elements.addEvent(this._mouseover, function(event){
			if (self.options.check && $check.call(this)) return false;
			this.getParent().addClass(self.options.classname);
		});
		this.elements.addEvent(this._mouseout, function(event){
			if (self.options.check && $check.call(this)) return false;
			this.getParent().removeClass(self.options.classname);
		});
	}
	
});

var $check = function(event){
	return this.className !== '';
};

})();