function ExtractWordManager() {
	this.initVariables();
}

ExtractWordManager.prototype.initVariables = function() {
	this.easyWordList = [];
	this.hardWordList = [];

	if(isKoreanTypingApp()) {
		this.easyWordList[0] = this.pickOutDifficulty(koreanBasicWordList, ExtractWordManager.DIFFICULTY_EASY);
		this.easyWordList[1] = this.pickOutDifficulty(koreanLeftUpperWordList, ExtractWordManager.DIFFICULTY_EASY);
		this.easyWordList[2] = this.pickOutDifficulty(koreanRightUpperWordList, ExtractWordManager.DIFFICULTY_EASY);
		this.easyWordList[3] = this.pickOutDifficulty(koreanSecondFingerWordList, ExtractWordManager.DIFFICULTY_EASY);
		this.easyWordList[4] = this.pickOutDifficulty(koreanLeftLowerWordList, ExtractWordManager.DIFFICULTY_EASY);
		this.easyWordList[5] = this.pickOutDifficulty(koreanRightLowerWordList, ExtractWordManager.DIFFICULTY_EASY);
		this.easyWordList[6] = this.pickOutDifficulty(koreanLeftUpperDoubleWordList, ExtractWordManager.DIFFICULTY_EASY);
		this.easyWordList[7] = this.pickOutDifficulty(koreanRightUpperDoubleWordList, ExtractWordManager.DIFFICULTY_EASY);
		// for(var i = 0; i < this.easyWordList.length; i++) {
		// 	console.log("this.easyWordList[" + i + "] length : " + this.easyWordList[i].length);
		// 	console.log("this.easyWordList[" + i + "] : " + this.easyWordList[i]);
		// }

		this.hardWordList[0] = this.pickOutDifficulty(koreanBasicWordList, ExtractWordManager.DIFFICULTY_HARD);
		this.hardWordList[1] = this.pickOutDifficulty(koreanLeftUpperWordList, ExtractWordManager.DIFFICULTY_HARD);
		this.hardWordList[2] = this.pickOutDifficulty(koreanRightUpperWordList, ExtractWordManager.DIFFICULTY_HARD);
		this.hardWordList[3] = this.pickOutDifficulty(koreanSecondFingerWordList, ExtractWordManager.DIFFICULTY_HARD);
		this.hardWordList[4] = this.pickOutDifficulty(koreanLeftLowerWordList, ExtractWordManager.DIFFICULTY_HARD);
		this.hardWordList[5] = this.pickOutDifficulty(koreanRightLowerWordList, ExtractWordManager.DIFFICULTY_HARD);
		this.hardWordList[6] = this.pickOutDifficulty(koreanLeftUpperDoubleWordList, ExtractWordManager.DIFFICULTY_HARD);
		this.hardWordList[7] = this.pickOutDifficulty(koreanRightUpperDoubleWordList, ExtractWordManager.DIFFICULTY_HARD);
		// for(var i = 0; i < this.hardWordList.length; i++) {
		// 	console.log("this.hardWordList[" + i + "] length : " + this.hardWordList[i].length);
		// 	console.log("this.hardWordList[" + i + "] : " + this.hardWordList[i]);
		// }
	} else {
		this.easyWordList[0] = this.pickOutDifficulty(englishBasicWordList, ExtractWordManager.DIFFICULTY_EASY);
		this.easyWordList[1] = this.pickOutDifficulty(englishLeftUpperWordList, ExtractWordManager.DIFFICULTY_EASY);
		this.easyWordList[2] = this.pickOutDifficulty(englishRightUpperWordList, ExtractWordManager.DIFFICULTY_EASY);
		this.easyWordList[3] = this.pickOutDifficulty(englishSecondFingerWordList, ExtractWordManager.DIFFICULTY_EASY);
		this.easyWordList[4] = this.pickOutDifficulty(englishLeftLowerWordList, ExtractWordManager.DIFFICULTY_EASY);
		this.easyWordList[5] = this.pickOutDifficulty(englishRightLowerWordList, ExtractWordManager.DIFFICULTY_EASY);
		// for(var i = 0; i < this.easyWordList.length; i++) {
		// 	console.log("this.easyWordList[" + i + "] length : " + this.easyWordList[i].length);
		// 	console.log("this.easyWordList[" + i + "] : " + this.easyWordList[i]);
		// }

		this.hardWordList[0] = this.pickOutDifficulty(englishBasicWordList, ExtractWordManager.DIFFICULTY_HARD);
		this.hardWordList[1] = this.pickOutDifficulty(englishLeftUpperWordList, ExtractWordManager.DIFFICULTY_HARD);
		this.hardWordList[2] = this.pickOutDifficulty(englishRightUpperWordList, ExtractWordManager.DIFFICULTY_HARD);
		this.hardWordList[3] = this.pickOutDifficulty(englishSecondFingerWordList, ExtractWordManager.DIFFICULTY_HARD);
		this.hardWordList[4] = this.pickOutDifficulty(englishLeftLowerWordList, ExtractWordManager.DIFFICULTY_HARD);
		this.hardWordList[5] = this.pickOutDifficulty(englishRightLowerWordList, ExtractWordManager.DIFFICULTY_HARD);
		// for(var i = 0; i < this.hardWordList.length; i++) {
		// 	console.log("this.hardWordList[" + i + "] length : " + this.hardWordList[i].length);
		// 	console.log("this.hardWordList[" + i + "] : " + this.hardWordList[i]);
		// }
	}
}

ExtractWordManager.prototype.getWordLevelCount = function() {
	// console.log("this.easyWordList.length : " + this.easyWordList.length);
	// console.log("this.hardWordList.length : " + this.hardWordList.length);

	var wordLevelCount = this.easyWordList.length;
	if(wordLevelCount < this.hardWordList.length)
		wordLevelCount = this.hardWordList.length;

	return wordLevelCount;
}

ExtractWordManager.prototype.pickOutDifficulty = function(wordList, difficultyForLevel) {
	var pickOutWordList = [];

	var count = wordList.length;
	var index = 0;
	for(var i = 0; i < count; i++) {
		var word = wordList[i];
		if(this.isValidWordForLevel(word, difficultyForLevel)) {
			pickOutWordList[index] = word;
			index++;
		}
	}

	return pickOutWordList;
}


ExtractWordManager.prototype.isValidWordForLevel = function(word, difficultyForLevel) {
	// console.log("word : " + word);
	// console.log("difficultyForLevel : " + difficultyForLevel);
	if(word == "")
		return false;

	var wordLength = word.length;

	if(difficultyForLevel == ExtractWordManager.DIFFICULTY_EASY) {
		var maxWordLength = 0;

		if(isKoreanTypingApp()) {
			maxWordLength = ExtractWordManager.DIFFICULTY_EASY_KOREAN_WORD_LENGTH;
		} else {
			maxWordLength = ExtractWordManager.DIFFICULTY_EASY_ENGLISH_WORD_LENGTH;
			// console.log("wordLength : " + wordLength);
			// console.log("maxWordLength : " + maxWordLength);
		}

		if(wordLength <= maxWordLength)
			return true;
		else
			return false;
	} else {
		var minWordLength = 0;
		// console.log("wordLength : " + wordLength);

		if(isKoreanTypingApp()) {
			minWordLength = ExtractWordManager.DIFFICULTY_EASY_KOREAN_WORD_LENGTH;
		} else {
			minWordLength = ExtractWordManager.DIFFICULTY_EASY_ENGLISH_WORD_LENGTH;
		}
		// console.log("minWordLength : " + minWordLength);

		if(wordLength > minWordLength)
			return true;
		else
			return false;
	}

}

ExtractWordManager.prototype.getWord = function(wordLevel, difficultyForLevel) {
	// console.log("wordLevel : " + wordLevel);
	// console.log("difficultyForLevel : " + difficultyForLevel);

	if(this.easyWordList[wordLevel] == undefined || this.hardWordList[wordLevel] == undefined) {
		console.log("====== Error ======");
		console.log("wordLevel : " + wordLevel);
		console.log("difficultyForLevel : " + difficultyForLevel);
	}

	var word = "";
	if(difficultyForLevel == ExtractWordManager.DIFFICULTY_EASY)
		word = this.spliceRandomWord(this.easyWordList[wordLevel]);
	else
		word = this.spliceRandomWord(this.hardWordList[wordLevel]);

	return word;
}

ExtractWordManager.prototype.spliceRandomWord = function(wordList) {
	// console.log("slice before : " + wordList);
	var randomIndex = Math.floor(Math.random() * wordList.length);
	word = wordList.splice(randomIndex, 1);
	// console.log("slice after : " + wordList);
	return word;
}


ExtractWordManager.prototype.giveBackWord = function(word, wordLevel, difficultyForLevel) {
	// console.log("remove : " + wordLevel + ", " + word);

	// console.log("push before : " + this.easyWordList[wordLevel]);
	if(difficultyForLevel == ExtractWordManager.DIFFICULTY_EASY)
		word = this.easyWordList[wordLevel].push(word);
	else
		word = this.hardWordList[wordLevel].push(word);
	// console.log("push after : " + this.easyWordList[wordLevel]);
}


ExtractWordManager.DIFFICULTY_EASY		= 0;
ExtractWordManager.DIFFICULTY_HARD		= 1

ExtractWordManager.DIFFICULTY_EASY_KOREAN_WORD_LENGTH	= 2;
ExtractWordManager.DIFFICULTY_EASY_ENGLISH_WORD_LENGTH	= 4;