function RankingBoard(type) {
	// ranking text
	var playingAppID = sessionStorageManager.getPlayingAppID();
	var rankingTextOffsetY = game.world.height / 2 + 105;
	this.rankingHourTexts = new Array();
	this.rankingDayTexts = new Array();
	this.rankingMonthTexts = new Array();
	for(var i = 0; i < RankingBoard.RANK_COUNT; i++) {
		var posY = rankingTextOffsetY + (i % 10) * 30;
		this.rankingHourTexts[i] = new RankingText(RankingText.PLACE_FOR_RESULT, 290, posY, playingAppID);
		this.rankingDayTexts[i] = new RankingText(RankingText.PLACE_FOR_RESULT, 530, posY, playingAppID);
		this.rankingMonthTexts[i] = new RankingText(RankingText.PLACE_FOR_RESULT, 770, posY, playingAppID);
	}

	if(type === RecordBoard.TYPE_SAMPLE) {
		this.printSample();
		return;
	}

	this.makeMedalSprites();

	this.dbConnectManager = new DBConnectManager();

	this.dbService = new DBService();
	this.dbService.setMaestroID(sessionStorageManager.getMaestroID());
	this.dbService.setPlayerID(sessionStorageManager.getPlayerID());

	setTimeout(
		(function() {
			this.requestRanking(DBConnectManager.TYPE_MY_RANKING_HOUR);
			this.requestRanking(DBConnectManager.TYPE_MY_RANKING_DAY);
			this.requestRanking(DBConnectManager.TYPE_MY_RANKING_MONTH);
		}).bind(this),

		RecordBoard.DELAY_UPDATING_RESULT_RECORD_MS
	);
}


RankingBoard.prototype.requestRanking = function(type) {
	var today = new Date();
	var date = DateUtil.getYYYYMMDD(today);
	var time = DateUtil.getHHMMSS(today);

	if(isTypingExamApp()) {
		this.dbService.requestTypingExamRanking(
			type,
			sessionStorageManager.getWritingID(),
			date,
			time,
			(function(type, rankingRecordManager) {
				this.onReceiveRankingData(type, rankingRecordManager);
			}).bind(this),
			(function(jsonData) {
				console.log(jsonData);
			}).bind(this)
		);
	} else {
		this.dbConnectManager.requestRanking(
			type,
			sessionStorageManager.getMaestroID(),
			date,
			time,
			(function(type, rankingRecordManager) {
				this.onReceiveRankingData(type, rankingRecordManager);
			}).bind(this)
		);
	}
}

RankingBoard.prototype.onReceiveRankingData = function(type, rankingRecordManager) {
	if(rankingRecordManager.getCount() == 0) {
		// console.log("ranking board - no data");
		return;
	}

	var beginIndex = this.getBeginIndex(rankingRecordManager);
	var endIndex = this.getEndIndex(rankingRecordManager);

	for(var i = 0; i < endIndex - beginIndex; i++) {
		var index = beginIndex + i;
		var data = rankingRecordManager.getAt(index);
		this.printRecord(type, i, data);
	}

	switch(type) {
		case DBConnectManager.TYPE_MY_RANKING_HOUR:
		this.showMedal(this.medalHour, this.getMyRank(rankingRecordManager));
		break;

		case DBConnectManager.TYPE_MY_RANKING_DAY:
		this.showMedal(this.medalDay, this.getMyRank(rankingRecordManager));
		break;

		case DBConnectManager.TYPE_MY_RANKING_MONTH:
		this.showMedal(this.medalMonth, this.getMyRank(rankingRecordManager));
		break;

	}
}

RankingBoard.prototype.getMyRank = function(rankingRecordManager) {
	var playerID = Number(sessionStorageManager.getPlayerID());

	for(var i = 0; i < rankingRecordManager.getCount(); i++) {
		var data = rankingRecordManager.getAt(i);
		var playerIDNo = Number(data["playerID"]);
		if(playerIDNo === playerID)
			return i + 1;
	}

	return -1;
}

RankingBoard.prototype.getBeginIndex = function(rankingRecordManager) {
	var rankingRecordCount = rankingRecordManager.getCount();
	var myRank = this.getMyRank(rankingRecordManager);
	var myRankIndex = myRank - 1;

	var startIndex = 0;
	var endIndex = rankingRecordCount;
	if(rankingRecordCount > 7) {
		if(myRank < rankingRecordCount - 3) {		// my rank is better than the worst 3
			if(myRank < 5) {
				startIndex = 0;
				endIndex = rankingRecordCount > 7 ? 7 : rankingRecordCount;
			} else {
				startIndex = myRankIndex - 3;
				endIndex = myRankIndex + 4;
			}
		} else {		// my rank is in the worst 3
			startIndex = rankingRecordCount > 7 ? rankingRecordCount - 7 : 0;
			endIndex = rankingRecordCount;
		}
	}

	return startIndex;
}

RankingBoard.prototype.getEndIndex = function(rankingRecordManager) {
	var rankingRecordCount = rankingRecordManager.getCount();
	var myRank = this.getMyRank(rankingRecordManager);
	var myRankIndex = myRank - 1;

	var startIndex = 0;
	var endIndex = rankingRecordCount;
	if(rankingRecordCount > 7) {
		if(myRank < rankingRecordCount - 3) {		// my rank is better than the worst 3
			if(myRank < 5) {
				startIndex = 0;
				endIndex = rankingRecordCount > 7 ? 7 : rankingRecordCount;
			} else {
				startIndex = myRankIndex - 3;
				endIndex = myRankIndex + 4;
			}
		} else {		// my rank is in the worst 3
			startIndex = rankingRecordCount > 7 ? rankingRecordCount - 7 : 0;
			endIndex = rankingRecordCount;
		}
	}

	return endIndex;
}


RankingBoard.prototype.printRecord = function(type, index, data) {
	var targetText = null;
	switch(type) {
		case DBConnectManager.TYPE_MY_RANKING_HOUR:
		targetText = this.rankingHourTexts;
		break;

		case DBConnectManager.TYPE_MY_RANKING_DAY:
		targetText = this.rankingDayTexts;
		break;

		case DBConnectManager.TYPE_MY_RANKING_MONTH:
		targetText = this.rankingMonthTexts;
		break;
	}

	targetText[index].setContents(data.playerID, data.rank, data.playerName, data.bestRecord);
}

RankingBoard.prototype.getPosX = function(type) {
	var posX = 0;

	switch(type) {
		case DBConnectManager.TYPE_MY_RANKING_HOUR:
		case DBConnectManager.TYPE_ALL_RANKING_HOUR:
		posX = 330;
		break;

		case DBConnectManager.TYPE_MY_RANKING_DAY:
		case DBConnectManager.TYPE_ALL_RANKING_DAY:
		posX = 560;
		break;

		case DBConnectManager.TYPE_MY_RANKING_MONTH:
		case DBConnectManager.TYPE_ALL_RANKING_MONTH:
		posX = 790;
	}

	return posX;
}

RankingBoard.prototype.getPosY = function(index) {
	return game.world.height / 2 + 90 + 30 * index;
}

RankingBoard.prototype.printSample = function() {
	// TYPE_MY_RANKING_HOUR
	this.printRecord(
		DBConnectManager.TYPE_MY_RANKING_HOUR, 0,
		new RankingRecord(1, 0, "홍길동", 1080)
	);
	this.printRecord(
		DBConnectManager.TYPE_MY_RANKING_HOUR, 1,
		new RankingRecord(2, 0, "3-1김영희", 860)
	);
	this.printRecord(
		DBConnectManager.TYPE_MY_RANKING_HOUR, 2,
		new RankingRecord(3, 0, "6-3이철수", 480)
	);


	// TYPE_MY_RANKING_DAY
	this.printRecord(
		DBConnectManager.TYPE_MY_RANKING_DAY, 0,
		new RankingRecord(1, 0, "050215", 1580)
	);
	this.printRecord(
		DBConnectManager.TYPE_MY_RANKING_DAY, 1,
		new RankingRecord(2, 0, "홍길동", 1080)
	);
	this.printRecord(
		DBConnectManager.TYPE_MY_RANKING_DAY, 2,
		new RankingRecord(3, 0, "3-1김영희", 860)
	);
	this.printRecord(
		DBConnectManager.TYPE_MY_RANKING_DAY, 3,
		new RankingRecord(4, 0, "6-3이철수", 480)
	);

	// TYPE_MY_RANKING_MONTH
	this.printRecord(
		DBConnectManager.TYPE_MY_RANKING_MONTH, 0,
		new RankingRecord(1, 0, "050215", 1580)
	);
	this.printRecord(
		DBConnectManager.TYPE_MY_RANKING_MONTH, 1,
		new RankingRecord(2, 0, "홍길동", 1080)
	);
	this.printRecord(
		DBConnectManager.TYPE_MY_RANKING_MONTH, 2,
		new RankingRecord(3, 0, "3-1김영희", 860)
	);
	this.printRecord(
		DBConnectManager.TYPE_MY_RANKING_MONTH, 3,
		new RankingRecord(4, 0, "6-3이철수", 480)
	);
}


RankingBoard.loadResources = function() {
	game.load.image('medal_gold', '../../../resources/image/ui/medal_gold.png');
	game.load.image('medal_silver', '../../../resources/image/ui/medal_silver.png');
	game.load.image('medal_bronze', '../../../resources/image/ui/medal_bronze.png');
}

RankingBoard.prototype.makeMedalSprites = function() {
	var rankAreaPositionY = 630;
	this.medalHour = game.add.image(380, rankAreaPositionY, 'medal_gold');
	this.medalHour.anchor.set(0.5);
	this.medalHour.alpha = 0;

	this.medalDay = game.add.image(625, rankAreaPositionY, 'medal_gold');
	this.medalDay.anchor.set(0.5);
	this.medalDay.alpha = 0;

	this.medalMonth = game.add.image(860, rankAreaPositionY, 'medal_gold');
	this.medalMonth.anchor.set(0.5);
	this.medalMonth.alpha = 0;
}

RankingBoard.prototype.showMedal = function(medal, myRank) {
	if(myRank > 3) {
		medal.alpha = 0;
		return;
	}

	if(myRank == 1)
		medal.loadTexture("medal_gold");
	else if(myRank == 2)
		medal.loadTexture("medal_silver");
	else if(myRank == 3)
		medal.loadTexture("medal_bronze");

	medal.alpha = 1;
	medal.scale.setTo(0.5);
	game.add.tween(medal.scale).to( {x: 0.7, y: 0.7}, 1000, Phaser.Easing.Bounce.Out, true);
}

RankingBoard.RANK_COUNT	= 7;