function StageTimer(stageTimerSec, onTimeOver) {
	this.stageTimerSec = stageTimerSec;
	this.onTimeOver = onTimeOver;

	this.isPaused = false;
	this.timeLeft = this.stageTimerSec;

	var fontStyle = StageTimer.DEFAULT_TEXT_FONT;

	fontStyle.align = "right";
	fontStyle.boundsAlignH = "right";
	this.timerText = game.add.text(game.world.width - 300, 0, "", fontStyle)
		.setTextBounds(0, 0, 200, StageTimer.FONT_HEIGHT_PX);

	// var grd = this.label.context.createLinearGradient(0, 0, 0, StageTimer.FONT_HEIGHT_PX);
	// grd.addColorStop(0, '#8ED6FF');
	// grd.addColorStop(1, '#004CB3');
	// this.label.fill = grd;
	// this.scoreText.fill = grd;

	// this.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
	// this.label.stroke = '#000';
	// this.label.strokeThickness = 3;

	this.timerEvent = null;

	var textStyle = { font: "bold 52px Arial", fill: "#ffd700", align: "center", boundsAlignH: "center", boundsAlignV: "middle" };
	this.bonusTimeText = game.add.text(game.world.centerX, game.world.centerY, "", textStyle);
	this.bonusTimeText.alpha = 0;
	this.bonusTimeText.anchor.set(0.5);
	this.bonusTimeText.stroke = '#000';
	this.bonusTimeText.strokeThickness = 6;
	this.bonusTimeText.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
};

StageTimer.prototype.setDisplayType = function(type) {
	this.displayType = type;
}

StageTimer.prototype.start = function() {
	this.timeLeft = this.stageTimerSec;
	this.printTime();
	if(this.timerEvent === null)
		this.timerEvent = game.time.events.loop(Phaser.Timer.SECOND, this.updateTimer, this);
}

StageTimer.prototype.pause = function() {
	this.isPaused = true;
}

StageTimer.prototype.resume = function() {
	this.isPaused = false;
}

StageTimer.prototype.stop = function() {
	if(this.timerEvent)
		this.removeTimer();
	this.timerText.text = "시간 끝";
}

StageTimer.prototype.updateTimer = function() {
	if(this.isPaused == true)
		return;

	this.timeLeft--;
	if(this.timeLeft === 0) {
		this.stop();
		this.onTimeOver();
	} else {
		this.printTime();
	}
}

StageTimer.prototype.printTime = function() {
	if(this.displayType == StageTimer.DISPLAY_TYPE_SEC) {
		this.timerText.text = this.timeLeft.toString() + "초";
		return;
	}

	var hours = Math.floor(this.timeLeft / 60 / 60);
	var minutes = Math.floor(this.timeLeft / 60);
	var seconds = this.timeLeft % 60;

	// console.log("hours : " + hours);
	// console.log("minutes : " + minutes);
	// console.log("seconds : " + seconds);

	this.timerText.text = "";
	var timeText = "";

	if(hours > 0)
		timeText = hours + "시간";

	if(minutes > 0) {
		if(timeText != "")
			timeText += " ";

		timeText = minutes + "분";
	}

	if(seconds > 0) {
		if(timeText != "")
			timeText += " ";

		timeText += seconds + "초";
	}

	this.timerText.text = timeText;
}

StageTimer.prototype.removeTimer = function() {
	game.time.events.remove(this.timerEvent);
	this.timerEvent = null;
}

StageTimer.prototype.addTime = function(timeSec) {
	this.timeLeft += timeSec;
	this.printTime();
}

StageTimer.prototype.addBonusTime = function(timeSec) {
	if(timeSec == 0)
		return;

	this.addTime(timeSec);

	game.world.bringToTop(this.bonusTimeText);
	this.bonusTimeText.text = "시간 보너스\n+" + timeSec + "초 추가";
	this.bonusTimeText.alpha = 1;
	game.add.tween(this.bonusTimeText).to({alpha: 0}, Phaser.Timer.SECOND, Phaser.Easing.Quintic.In, true);
}


StageTimer.DISPLAY_TYPE_NON_SEC	= 0;
StageTimer.DISPLAY_TYPE_SEC		= 1;

StageTimer.FONT_HEIGHT_PX		= 70;

StageTimer.DEFAULT_TEXT_FONT	= {
	font: "38px Arial",
	align: "center",
	boundsAlignH: "center",		// left, center. right
	boundsAlignV: "middle", 	// top, middle, bottom
	fill: "#fff"
};