var JetTimer = {
	_count: null,
	_disp: null,
	_timerId: null,
	reset: function(aDisp) {
		this._count = 3 * 60;
		this._disp = aDisp;
		this._disp.text("JetTimer");
	},
	start: function() {
		if (this._timerId)
			return;
		this._timerId = setInterval(function(self) { self._countdown(); }, 1000, this);
	},
	_countdown: function() {
		--this._count;
		var m = Math.floor(this._count / 60);
		var s = this._count % 60;
		this._disp.text("あと " + (m > 0 ? m.toString() + "分" : "") + s.toString() + "秒");
		if (this._count == 0) {
			jetpack.notifications.show("タイムアップ！");
			this.stop();
		}
	},
	stop: function() {
		if (this._timerId) {
			clearInterval(this._timerId);
			this._timerId = null;
		}
		this.reset(this._disp);
	},
};

jetpack.statusBar.append({
	html: '<span id="disp" style="font-size: large; font-weight: bold;" />',
	width: 150,
	onReady: function(doc) {
		JetTimer.reset($("#disp", doc));
		$("#disp", doc).click(function() { JetTimer.start(); });
	},
});

