/*
---

name: Element.wait

license: MIT-style license.

authors: Scott Kyle

requires: Core/Element

provides: Element.wait

---
*/

(function(){

var Proxy = function(el, time){
	var stack = this.$stack = [];

	stack.each.delay(time, stack, function(info){
		el = el[info.name].apply(el, info.args);
	});
};

var fake = function(method, name){
	return (typeOf(method) != 'function') ? null : function(){
		this.$stack.push({name: name, args: arguments});
		return this;
	};
};

var proto = Proxy.prototype = Object.map(Element.prototype, fake);

Element.mirror(function(name, method){
	proto[name] = fake(method, name);
});

[Element, Elements].invoke('implement', 'wait', function(time){
	return new Proxy(this, time || 500);
});

})();

