if(!window.lim){ var lim = {utils:{}}; }
if(!lim.utils){ lim.utils = {}; }

;(function(scope){

	var Queue = function(){
			this.data = { 'default': [] };
		},
		is = function(p_value, p_is) {
			return p_value && p_value.constructor === p_is;
		};
	Queue.prototype = {
		add: function(p_method, p_params, p_scope, p_name){
			if(p_name && !this.data[p_name]){
				this.data[p_name] = [];
			}
			p_name = p_name || 'default';
			p_params = p_params || [];
			
			if(is(p_method, Function)){
				this.data[p_name].push({
					'method': p_method,
					'params': is(p_params, Array) ? p_params : [p_params],
					'scope': p_scope
				});
			}
			return this;
		},
		run: function(p_name) {
			p_name = p_name || 'default';
			var curr;
			for(var i=0, len=this.data[p_name].length; i < len; i++){
				curr = this.data[p_name][i];
				curr.method.apply(curr.scope, curr.params);
			}
			this.data[p_name].length = 0;
		}
	};
	scope.Queue = Queue;
})(
	lim.utils
);
