1 /* limits calls in delay ms.
  2 if function is called before delay end, waits and call only last at delay end */
  3 var YCallsLimit=function(owner,delay){
  4 	this.requests = [];
  5 	this.owner = owner;
  6 	this.delay = delay;
  7 	this.req=function(Function,args){
  8 		var req = {
  9 			first	: true,
 10 			timer	: null,
 11 			args	: args,
 12 			lastTime: new Date().getTime()
 13 		};
 14 		if(!this.requests[Function]){
 15 			this.requests[Function] = req;
 16 		}else{
 17 			this.requests[Function].args = args;
 18 			req = this.requests[Function];
 19 		}
 20 		if(req.timer){
 21 			req.first = false;
 22 		}else{
 23 			req.first = true;
 24 			req.timer = YTimer.timeout(this.delay,function(dat){dat.own._flush(dat.funk);},{own:this,funk:Function});
 25 			this._eval(Function);
 26 		}
 27 	};
 28 	this._eval=function(Function){
 29 		var argz = [];
 30 		for(var i=0;i<this.requests[Function].args.length;i++){argz.push("this.requests['"+Function+"'].args["+i+"]");}
 31 		//_alert("this.owner."+Function+"("+argz.join(',')+");");
 32 		eval("this.owner."+Function+"("+argz.join(',')+");");
 33 	};
 34 	this._flush=function(Function){
 35 		this.requests[Function].timer = null;
 36 		if(!this.requests[Function].first){
 37 			this._eval(Function);
 38 		}
 39 	};
 40 };
 41