﻿/**
 * 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/02/08
 *
 * @author Blair Mitchelmore
 * @version 1.1.2
 *
 **/
;
jQuery.fn.extend({everyTime:function(B,C,D,E,A){return this.each(function(){jQuery.timer.add(this,B,C,D,E,A)
})
},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 A=this.regex.exec(jQuery.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(E,C,H,G,B,F){var A=0;
if(jQuery.isFunction(H)){if(!B){B=G
}G=H;
H=C
}C=jQuery.timer.timeParse(C);
if(typeof C!="number"||isNaN(C)||C<=0){return 
}if(B&&B.constructor!=Number){F=!!B;
B=0
}B=B||0;
F=F||false;
var D=jQuery.data(E,this.dataKey)||jQuery.data(E,this.dataKey,{});
if(!D[H]){D[H]={}
}G.timerID=G.timerID||this.guid++;
var I=function(){if(F&&this.inProgress){return 
}this.inProgress=true;
if((++A>B&&B!==0)||G.call(E,A)===false){jQuery.timer.remove(E,H,G)
}this.inProgress=false
};
I.timerID=G.timerID;
if(!D[H][G.timerID]){D[H][G.timerID]=window.setInterval(I,C)
}this.global.push(E)
},remove:function(C,B,D){var E=jQuery.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){jQuery.removeData(C,this.dataKey)
}}}}});
jQuery(window).bind("unload",function(){jQuery.each(jQuery.timer.global,function(A,B){jQuery.timer.remove(B)
})
});
