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 toTime (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(", "); }