/*
 * 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
 *
 */
jQuery.fn.extend({everyTime:function(a,b,c,d){return this.each(function(){jQuery.timer.add(this,a,b,c,d)})},oneTime:function(a,b,c){return this.each(function(){jQuery.timer.add(this,a,b,c,1)})},stopTime:function(a,b){return this.each(function(){jQuery.timer.remove(this,a,b)})}});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(c){if(c==undefined||c==null){return null}var b=this.regex.exec(jQuery.trim(c.toString()));if(b[2]){var a=parseFloat(b[1]);var d=this.powers[b[2]]||1;return a*d}else{return c}},add:function(e,c,d,g,h){var b=0;if(jQuery.isFunction(d)){if(!h){h=g}g=d;d=c}c=jQuery.timer.timeParse(c);if(typeof c!="number"||isNaN(c)||c<0){return}if(typeof h!="number"||isNaN(h)||h<0){h=0}h=h||0;var a=jQuery.data(e,this.dataKey)||jQuery.data(e,this.dataKey,{});if(!a[d]){a[d]={}}g.timerID=g.timerID||this.guid++;var f=function(){if((++b>h&&h!==0)||g.call(e,b)===false){jQuery.timer.remove(e,d,g)}};f.timerID=g.timerID;if(!a[d][g.timerID]){a[d][g.timerID]=window.setInterval(f,c)}this.global.push(e)},remove:function(d,c,e){var a=jQuery.data(d,this.dataKey),b;if(a){if(!c){for(c in a){this.remove(d,c,e)}}else{if(a[c]){if(e){if(e.timerID){window.clearInterval(a[c][e.timerID]);delete a[c][e.timerID]}}else{for(var e in a[c]){window.clearInterval(a[c][e]);delete a[c][e]}}for(b in a[c]){break}if(!b){b=null;delete a[c]}}}for(b in a){break}if(!b){jQuery.removeData(d,this.dataKey)}}}}});jQuery(window).bind("unload",function(){jQuery.each(jQuery.timer.global,function(a,b){jQuery.timer.remove(b)})});
