SL.elements = {};

(function() {

	SL.elements.createBlindRow = function(origRow) {

		var numCols = 0;

		var children = origRow.childElements();
		for ( var i = 0; i < children.length; i++) {
			var colspan = children[i].readAttribute('colspan');
			numCols += colspan ? parseInt(colspan) : 1;
		}

		var e = new Element('tr');
		var td = new Element('td', {
			colspan : numCols
		});

		td.setStyle({
			margin : '0',
			padding : '0'
		});

		e.appendChild(td);

		return e;
	};

	SL.Element = Class.create({

		isElement : true,

		initialize : function(e, config) {
			this.e = $(e);
			this.id = this.e.identify();
			this.config = $H(config);

			this.init();

		},

		init : function() {
		},

		destroy : function() {
			this.cleanup();
		},

		cleanup : function() {
		},

		connectDestroy : function(triggerElement) {
			if (!triggerElement) {
				return;
			}
			var e = $(triggerElement);
			var h = e.retrieve('sl_delete_notify');
			if (!h) {
				h = $H();
				e.store('sl_delete_notify', h);
				e.addClassName('sljs__delete_notify__');
			}
			if (!h.get(this.id)) {
				h.set(this.id, this);
			}
		},

		_destroy : function() {
			if (this.e.parentNode) {
				this.e.remove();
			}
			// async test do prevent leaks
			(function(id) {
				var e = $(id);
				if (e && e.parentNode) {
					e.remove();
				}
			}.curry(this.id).defer());
		}
	});

})();

