var Meter = function() { var meterLabel, meterCurrent, meterStep, meterDuration, meterCallback, meterActive; this.isRunning = function() { return meterActive; }; this.set = function(display, duration, callback) { var bar = document.getElementById("progressBar"); bar.style.visibility = "visible"; var label = document.getElementById("progressLabel"); label.style.visibility = "visible"; label.innerHTML = display; if (duration == 0) { meterStep = 0; meterCurrent = 0; } else { meterDuration = duration; meterCallback = callback; meterCurrent = 0; meterStep = 100 / meterDuration; } bar.value = meterCurrent; meterActive = true; }; this.hide = function() { document.getElementById("progressBar").style.visibility = "hidden"; document.getElementById("progressLabel").style.visibility = "hidden"; meterActive = false; }; this.update = function() { if (meterActive) { meterCurrent += meterStep; document.getElementById("progressBar").value = meterCurrent; if (meterCurrent >= 100) { meterCallback(); this.hide(); meterCallback = null; } } }; this.save = function() { //localStorage. }; this.load = function() { }; }; var meter = new Meter();