﻿jQuery.fn.extend({ everyTime: function(b, a, d, c, e) { return this.each(function() { jQuery.timer.add(this, b, a, d, c, e) }) }, oneTime: function(b, a, d) { return this.each(function() { jQuery.timer.add(this, b, a, d, 1) }) }, stopTime: function(b, a) { return this.each(function() { jQuery.timer.remove(this, b, a) }) } });
jQuery.extend({ timer: { global: [], guid: 1, dataKey: "jQuery.timer", regex: /^([0-9]+(?:\.[0-9]*)?)\s*(.*s)?$/, powers: { ms: 1, cs: 10, ds: 100, s: 1000, das: 10000, hs: 100000, ks: 1000000 }, timeParse: function(b) { if (b == undefined || b == null) return null; var a = this.regex.exec(jQuery.trim(b.toString())); if (a[2]) { b = parseFloat(a[1]); a = this.powers[a[2]] || 1; return b * a } else return b }, add: function(b, a, d, c, e, f) {
	var h = 0; if (jQuery.isFunction(d)) { e || (e = c); c = d; d = a } a = jQuery.timer.timeParse(a); if (!(typeof a != "number" || isNaN(a) || a <= 0)) {
		if (e &&
e.constructor != Number) { f = !!e; e = 0 } e = e || 0; f = f || false; var g = jQuery.data(b, this.dataKey) || jQuery.data(b, this.dataKey, {}); g[d] || (g[d] = {}); c.timerID = c.timerID || this.guid++; var i = function() { if (!(f && this.inProgress)) { this.inProgress = true; if (++h > e && e !== 0 || c.call(b, h) === false) jQuery.timer.remove(b, d, c); this.inProgress = false } }; i.timerID = c.timerID; g[d][c.timerID] || (g[d][c.timerID] = window.setInterval(i, a)); this.global.push(b)
	} 
}, remove: function(b, a, d) {
	var c = jQuery.data(b, this.dataKey), e; if (c) {
		if (a) {
			if (c[a]) {
				if (d) {
					if (d.timerID) {
						window.clearInterval(c[a][d.timerID]);
						delete c[a][d.timerID]
					} 
				} else for (d in c[a]) { window.clearInterval(c[a][d]); delete c[a][d] } for (e in c[a]) break; if (!e) { e = null; delete c[a] } 
			} 
		} else for (a in c) this.remove(b, a, d); for (e in c) break; e || jQuery.removeData(b, this.dataKey)
	} 
} }
}); jQuery(window).bind("unload", function() { jQuery.each(jQuery.timer.global, function(b, a) { jQuery.timer.remove(a) }) });
