window.requestAnimFrame = (function(){ return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function( callback ){ window.setTimeout(callback, 1000 / 60); }; })(); function pluralize (n, s) { return n + " " + (n == 1 ? s : s + "s"); } function timeInWords (time) { var str = []; time /= 1000; if (time > 86400) { str.push( pluralize( Math.floor(time / 86400), "day" ) ); } if (time > 3600) { str.push( pluralize( Math.floor(time / 3600) % 24, "hour" ) ); } if (time > 60) { str.push( pluralize( Math.floor(time / 60) % 60, "minute" ) ); } var seconds = Math.floor(100 * (time % 60)) / 100; seconds = (seconds + "").split("."); if (seconds.length == 1) seconds[1] = "00"; // if (seconds[0].length == 1) seconds[0] = "0" + seconds[0]; if (seconds[1].length == 1) seconds[1] = seconds[1] + "0"; str.push( pluralize( seconds[0] + "." + seconds[1], "second" ) ); return str.join(", "); } function timeInMillisecs (time) { var str = []; time /= 1000; if (time > 86400) { str.push( leading( time / 86400 ) ); } if (time > 3600) { str.push( leading( (time / 3600) % 24 ) ); } if (time > 60) { str.push( leading( (time / 60) % 60 ) ); } else { str.push( Math.floor( time / 60 ) ); } /* var seconds = Math.floor(10 * (time % 60)) / 10; seconds = (seconds + "").split("."); if (seconds.length == 1) seconds[1] = "0"; str.push( leading( time % 60 ) + "." + seconds[1] ); */ // str.push( leading( time % 60 ) ); var seconds = Math.floor(100 * (time % 60)) / 100; seconds = (seconds + "").split("."); if (seconds.length == 1) seconds[1] = "00"; if (seconds[0].length == 1) seconds[0] = "0" + seconds[0]; if (seconds[1].length == 1) seconds[1] = seconds[1] + "0"; str.push( seconds[0] + "." + seconds[1] ); return str.join(":"); } function leading(num) { num = Math.floor(num); return num < 10 ? "0" + num : num; }