(function(scope) {

	if (typeof scope.timeout != "undefined") return; 

	
	scope.timeout = function (func,delay) {
			// init
			if (typeof scope.timeout.count == "undefined") scope.timeout.count = 0; 	
			if (typeof scope.timeout.funcs == "undefined") scope.timeout.funcs = new Array(); 
			// set timeout
			if (typeof func =='string') return setTimeout(func, delay); 
			if (typeof func =='function') {
				scope.timeout.count++;
				scope.timeout.funcs[scope.timeout.count] = func;
				return setTimeout("window.timeout.funcs["+scope.timeout.count+"]();", delay);
			}
	}
	scope.interval = function (func,delay) {
			// init
			if (typeof scope.interval.count == "undefined") scope.interval.count = 0; 	
			if (typeof scope.interval.funcs == "undefined") scope.interval.funcs = new Array(); 
			// set interval
			if (typeof func =='string') return setInterval(func, delay); 
			if (typeof func =='function') {
				scope.interval.count++;
				scope.interval.funcs[scope.interval.count] = func;
				return setInterval("window.interval.funcs["+scope.interval.count+"]();", delay);
			}
	}
	scope.idle = function (func,delay) {
			// init
			if (typeof scope.idle.lasttimeout == "undefined") scope.idle.lasttimeout = null;
			if (typeof scope.idle.lastfunc == "undefined") scope.idle.lastfunc = null;
			// set idle timeout
			if (scope.idle.timeout) { clearTimeout(scope.idle.timeout); scope.idle.timeout = null; scope.idle.lastfunc = null; }
			if (typeof(func)=='string') { 
				scope.idle.timeout = setTimeout(func, delay); 
				return scope.idle.timeout;
			}		
			if (typeof(func)=='function') { 
				scope.idle.lastfunc = func;
				scope.idle.timeout = setTimeout("window.idle.lastfunc();", delay);
				return scope.idle.timeout;
			}
	}
	scope.clear = function (countdown) {
		clearInterval(countdown);
		clearTimeout(countdown);
	}		
	
})(window);