var CatalogRow = Class.create();

CatalogRow.prototype = {
	
	initialize: function(obj, check) {
		this.obj = $(obj);
		this.objClass = this.obj.className;
		this.check = $(check);
		this.linkOver = false;
		this.checkOver = false;

		this.initLink();
		this.registerEvents();
	},
	initLink: function() {
		this.link = null;
		if ((0 < this.obj.cells[0].childNodes.length) && ('A' == this.obj.cells[0].childNodes[0].nodeName)) {
			this.link = this.obj.cells[0].childNodes[0];
		}
	},
	registerEvents: function() {
		Event.observe(this.obj, 'mouseover', this.onMouseOver.bind(this));
		Event.observe(this.obj, 'mouseout', this.onMouseOut.bind(this));
		if (this.link) {
			Event.observe(this.link, 'mouseover', function() { this.linkOver = true; }.bind(this));
			Event.observe(this.link, 'mouseout', function() { this.linkOver = false; }.bind(this));
		}
		if (this.check) {
			Event.observe(this.obj, 'click', this.onClick.bind(this));
			Event.observe(this.check, 'mouseover', function() { this.checkOver = true; }.bind(this));
			Event.observe(this.check, 'mouseout', function() { this.checkOver = false; }.bind(this));
		}
	},
	onMouseOver: function() {
		this.obj.className = 'over';
	},
	onMouseOut: function() {
		if (!this.check || (this.check && !this.check.checked)) {
			this.obj.className = this.objClass;
		}
	},
	onClick: function() {
		if (!this.linkOver && !this.checkOver) this.check.checked = !(this.check.checked);
		this.obj.className = (this.check.checked ? 'over' : this.objClass);
	}

}