﻿/**
 * jQuery.timers - Timer abstractions for jQuery
 * Written by Blair Mitchelmore (blair DOT mitchelmore AT gmail DOT com)
 * Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).
 * Date: 2009/10/16
 *
 * @author Blair Mitchelmore
 * @version 1.2
 *
 **/
;jQueryNC.fn.extend({everyTime:function(a,b,c,d){return this.each(function(){jQueryNC.timer.add(this,a,b,c,d)})},oneTime:function(a,b,c){return this.each(function(){jQueryNC.timer.add(this,a,b,c,1)})},stopTime:function(a,b){return this.each(function(){jQueryNC.timer.remove(this,a,b)})}});jQueryNC.extend({timer:{global:[],guid:1,dataKey:"jQueryNC.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(c){if(c==undefined||c==null){return null}var a=this.regex.exec(jQueryNC.trim(c.toString()));if(a[2]){var b=parseFloat(a[1]);var d=this.powers[a[2]]||1;return b*d}else{return c}},add:function(d,b,c,f,h){var a=0;if(jQueryNC.isFunction(c)){if(!h){h=f}f=c;c=b}b=jQueryNC.timer.timeParse(b);if(typeof b!="number"||isNaN(b)||b<0){return}if(typeof h!="number"||isNaN(h)||h<0){h=0}h=h||0;var g=jQueryNC.data(d,this.dataKey)||jQueryNC.data(d,this.dataKey,{});if(!g[c]){g[c]={}}f.timerID=f.timerID||this.guid++;var e=function(){if((++a>h&&h!==0)||f.call(d,a)===false){jQueryNC.timer.remove(d,c,f)}};e.timerID=f.timerID;if(!g[c][f.timerID]){g[c][f.timerID]=window.setInterval(e,b)}this.global.push(d)},remove:function(c,b,d){var e=jQueryNC.data(c,this.dataKey),a;if(e){if(!b){for(b in e){this.remove(c,b,d)}}else{if(e[b]){if(d){if(d.timerID){window.clearInterval(e[b][d.timerID]);delete e[b][d.timerID]}}else{for(var d in e[b]){window.clearInterval(e[b][d]);delete e[b][d]}}for(a in e[b]){break}if(!a){a=null;delete e[b]}}}for(a in e){break}if(!a){jQueryNC.removeData(c,this.dataKey)}}}}});jQueryNC(window).bind("unload",function(){jQueryNC.each(jQueryNC.timer.global,function(a,b){jQueryNC.timer.remove(b)})});

