
(function($){$.cron=function(){if($.cron.on==false){$.cron.wait=setInterval('$.cron.init()',200);}else{$.cron.init();}};$.cron.version='0.1';$.cron.on=false;$.cron.running=false;$.cron.busy=false;$.cron.tab={onSecond:[],onMinute:[],onHour:[],onDay:[]};$.cron.others={};$.cron.main=function(){if($.cron.on==false){window.clearInterval($.cron.running);$.cron();}else{if($.cron.busy==false){$.cron.busy=true;$.each($.cron.tab,function(i,v){$.cron.dispatch(i);});$.cron.dispatchToOthers();$.cron.busy=false;}}};$.cron.init=function(){if($.cron.on==true){d=$.cron.d().getMilliseconds();if(d==0){$.cron.running=setInterval('$.cron.main();',1000);window.clearInterval($.cron.wait);$.cron.main();}else{setTimeout('$.cron.init()',(1000-d));}}};$.cron.dispatch=function(timing){d=new Date();general=null;switch(timing){case'onMinute':general=d.getSeconds();break;case'onHour':general=d.getMinutes();break;case'onDay':general=d.getHours();break;}
if($.cron.tab[timing].length>0){if(timing=='onSecond'){$.each($.cron.tab.onSecond,function(i,func){try{if(typeof(func)=='function'){func($.cron.d());func=null;}}catch(e){console.log(e);$.cron.tab.onSecond[i]=null;}});}else if(general==0){$.each($.cron.tab[timing],function(i,func){if(timing!='onSecond'){try{func($.cron.d());func=null;}catch(e){console.log(e);$.cron.tab[timing][i]=null;}}});}}};$.cron.dispatchToOthers=function(){$.each($.cron.others,function(i,v){if(v.next==null){v.next=v.timing;}
$('#tester').html(v.next);if(v.next==1000){v.next=v.timing;v.caller();}else{v.next=v.next-1000;}});};$.cron.register=function(timing,func,label){switch(timing){case'onSecond':$.cron.tab.onSecond.push(func);break;case'onMinute':$.cron.tab.onMinute.push(func);break;case'onHour':$.cron.tab.onHour.push(func);break;case'onDay':$.cron.tab.onDay.push(func);break;default:d=$.parseTime(timing);if(!label){label=Math.random()*d;}
$.cron.others[label]={'caller':func,'next':null,'timing':d,'label':label};break;}
if(!label){return{'event':timing,'index':$.cron.tab[timing].length-1};}else{return label;}};$.cron.deRegister=function(id){if(typeof(id)=='string'){if(typeof($.cron.tab[id])!='undefined'){$.cron.tab[id]=[];}else{$.each($.cron.others,function(i,v){if(v.label==id){$.cron.others[i]=null;}});}}else if(!id.index&&!id.event){throw('You must provide the object supplied to you by the $.cron.register() function');}else{$.cron.tab[id.event][id.index]=null;}};$.cron.once=function(timing,func){t=$.parseTime(timing);id=setTimeout(func,t);return id;};$.cron.d=function(){Date.prototype.daysAgo=function(t){return this.setTime((this.getTime()-(t*86400))*10);};Date.prototype.minutesAgo=function(t){return this.setTime((this.getTime()-(t*60))*10);};Date.prototype.hoursAgo=function(t){return this.setTime((this.getTime()-(t*3600))*10);};Date.prototype.daysTime=function(t){return this.setTime((this.getTime()+(t*86400))*10);};Date.prototype.minutesTime=function(t){return this.setTime((this.getTime()+(t*60))*10);};Date.prototype.hoursTime=function(t){return this.setTime((this.getTime()+(t*3600))*10);};return new Date();};$.parseTime=function(str){if(str.match(/\d{1,3}[s]/)){return Number(str.replace(/(\w){1,3}[s]/,'$1'))*1000;}
if(str.match(/\d{1,3}[m]/)){return(Number(str.replace(/(\d){1,3}[m]/,'$1'))*60)*1000;}
if(str.match(/\d{1,3}[h]/)){return((Number(str.replace(/(\d){1,3}[h]/,'$1'))*60)*60)*1000;}};$.cron.unLoad=function(){window.clearInterval($.cron.running);window.clearInterval($.cron.wait);};})(jQuery);window.onUnload=$.cron.unLoad();
