if (typeof(jx.Widget) == "undefined") {
	jx.Widget = {
		toString : function () {
			return "jx.Widget " + this.version + " (Copyright 2005 Troels Knak-Nielsen)";
		},
		version : "0.1"
	};
}

/**
  * Abstract baseclass for widgets
  */
jx.Widget.Base = function(args) {
	this.view = {};
	this._signalCache = [];
}
/**
  * Attach the controller to a HTMLElement in the DOM.
  */
jx.Widget.Base.prototype.attach = function(element) {
	throw new Error("jx.Widget.Base.prototype.attach is abstract");
}
/**
  * Remove the widget from the DOM.
  */
jx.Widget.Base.prototype.detach = function() {
	for (var i = 0, l = this._signalCache.length; i < l; ++i) {
		var cache = this._signalCache[i];
		MochiKit.Signal.disconnect(cache.src, cache.sig, cache.slot);
	}
	delete(this._signalCache);
}
/**
  * Attaches an event. Use this method to ensure cleanup through detach
  */
jx.Widget.Base.prototype.connect = function(src, sig, slot) {
	MochiKit.Signal.connect(src, sig, slot);
	this._signalCache.push({ src : src, sig : sig, slot : slot });
};

