/*!
 * JS Signals <http://millermedeiros.github.com/js-signals/>
 * Released under the MIT license <http://www.opensource.org/licenses/mit-license.php>
 * @author Miller Medeiros <http://millermedeiros.com/>
 * @version 0.5.3
 * @build 143 (02/21/2011 07:18 PM)
 */
var signals=(function(){var a={VERSION:"0.5.3"};function b(g,f,d,e,c){this._listener=f;this._isOnce=d;this.context=e;this._signal=g;this._priority=c||0}b.prototype={_isEnabled:true,execute:function(c){var d;if(this._isEnabled){d=this._listener.apply(this.context,c);if(this._isOnce){this.detach()}}return d},detach:function(){return this._signal.remove(this._listener)},getListener:function(){return this._listener},dispose:function(){this.detach();this._destroy()},_destroy:function(){delete this._signal;delete this._isOnce;delete this._listener;delete this.context},disable:function(){this._isEnabled=false},enable:function(){this._isEnabled=true},isEnabled:function(){return this._isEnabled},isOnce:function(){return this._isOnce},toString:function(){return"[SignalBinding isOnce: "+this._isOnce+", isEnabled: "+this._isEnabled+"]"}};a.Signal=function(){this._bindings=[]};a.Signal.prototype={_shouldPropagate:true,_isEnabled:true,_registerListener:function(g,f,e,d){if(typeof g!=="function"){throw new Error("listener is a required param of add() and addOnce() and should be a Function.")}var c=this._indexOfListener(g),h;if(c!==-1){h=this._bindings[c];if(h.isOnce()!==f){throw new Error("You cannot add"+(f?"":"Once")+"() then add"+(!f?"":"Once")+"() the same listener without removing the relationship first.")}}else{h=new b(this,g,f,e,d);this._addBinding(h)}return h},_addBinding:function(c){var d=this._bindings.length;do{--d}while(this._bindings[d]&&c._priority<=this._bindings[d]._priority);this._bindings.splice(d+1,0,c)},_indexOfListener:function(c){var d=this._bindings.length;while(d--){if(this._bindings[d]._listener===c){return d}}return -1},add:function(e,d,c){return this._registerListener(e,false,d,c)},addOnce:function(e,d,c){return this._registerListener(e,true,d,c)},remove:function(d){if(typeof d!=="function"){throw new Error("listener is a required param of remove() and should be a Function.")}var c=this._indexOfListener(d);if(c!==-1){this._bindings[c]._destroy();this._bindings.splice(c,1)}return d},removeAll:function(){var c=this._bindings.length;while(c--){this._bindings[c]._destroy()}this._bindings.length=0},getNumListeners:function(){return this._bindings.length},disable:function(){this._isEnabled=false},enable:function(){this._isEnabled=true},isEnabled:function(){return this._isEnabled},halt:function(){this._shouldPropagate=false},dispatch:function(d){if(!this._isEnabled){return}var c=Array.prototype.slice.call(arguments),f=this._bindings.slice(),e=this._bindings.length;this._shouldPropagate=true;do{e--}while(f[e]&&this._shouldPropagate&&f[e].execute(c)!==false)},dispose:function(){this.removeAll();delete this._bindings},toString:function(){return"[Signal isEnabled: "+this._isEnabled+" numListeners: "+this.getNumListeners()+"]"}};return a}());
