fbpx

Get These Resources on Sale!

SALE ENDS AT MIDNIGHT EST!

//###################################################################
// Author: ricocheting.com
// Version: v3.1
// Date: 2017-01-03
// Description: displays the amount of time until the “dateFuture” entered below.

var CDown = function() {
this.state=0;// if initialized
this.counts=[];// array holding countdown date objects and id to print to {d:new Date(2013,11,18,18,54,36), id:”countbox1″}
this.interval=null;// setInterval object
}

CDown.prototype = {
init: function(){
this.state=1;
var self=this;
this.interval=window.setInterval(function(){self.tick();}, 1000);
},
add: function(date,id){
this.counts.push({d:date,id:id});
this.tick();
if(this.state==0) this.init();
},
expire: function(idxs){
for(var x in idxs) {
this.display(this.counts[idxs[x]], “Sale Over!”);
this.counts.splice(idxs[x], 1);
}
},
format: function(r){
var pre=”,post=”,divide=’, ‘,
out=””;
if(r.h != 0){out += pre+r.h +” “+((r.h==1)?”hour”:”hours”)+post+divide;}
out += pre+r.m +” “+((r.m==1)?”min”:”mins”)+post+divide;
out += pre+r.s +” “+((r.s==1)?”sec”:”secs”)+post+divide;

return out.substr(0,out.length-divide.length);
},
math: function(work){
var y=w=d=h=m=s=ms=0;

ms=(“”+((work%1000)+1000)).substr(1,3);
work=Math.floor(work/1000);//kill the “milliseconds” so just secs

y=Math.floor(work/31536000);//years (no leapyear support)
w=Math.floor(work/604800);//weeks
d=Math.floor(work/86400);//days
h=Math.floor(work/3600);//hours
work=work%3600;

m=Math.floor(work/60);//minutes
work=work%60;

s=Math.floor(work);//seconds

return {y:y,w:w,d:d,h:h,m:m,s:s,ms:ms};
},
tick: function(){
var now=(new Date()).getTime(),
expired=[],cnt=0,amount=0;

if(this.counts)
for(var idx=0,n=this.counts.length; idx