var LANGUAGE_KOREAN		= "korean";
var LANGUAGE_ENGLISH	= "english";

var MODE_RELEASE		= "release";
var MODE_DEBUG			= "debug";
var runMode = MODE_DEBUG;

function isTddMode() {
	// console.log("debug mode ? " + runMode);
	if(typeof(tddMode) === "undefined")
		return false;

	if(tddMode == true)
		return true;

	return false;
}

function isDebugMode() {
	// console.log("debug mode ? " + runMode);
	return runMode == MODE_DEBUG ? true : false;
}

function isReleaseMode() {
	// console.log("release mode ? " + runMode);
	return runMode == MODE_RELEASE ? true : false;
}


var GAME_SCREEN_SIZE = { x: 1024, y: 768 }



var sessionStorageManager = new SessionStorageManager();

{
	if(isTddMode()) {
		console.log("Running in TDD mode");
	} else {
		if(isDebugMode()) {
			printSessionStorage();
		}

		if(sessionStorageManager.getMaestroID() === null && !isLogin()) {
			goLogin();
		}
	}
}

function printSessionStorage() {
	console.log("maestroName : " + sessionStorageManager.getMaestroName());
	console.log("maestroID : " + sessionStorageManager.getMaestroID());
	console.log("maestroAccountType : " + sessionStorageManager.getMaestroAccountType());
	console.log("playerName : " + sessionStorageManager.getPlayerName());
	console.log("playerID : " + sessionStorageManager.getPlayerID());
	console.log("playerAccountType : " + sessionStorageManager.getPlayerAccountType());
	console.log("playingAppID : " + sessionStorageManager.getPlayingAppID());
	console.log("playingAppName : " + sessionStorageManager.getPlayingAppName());
	console.log("playingAppKoreanName : " + sessionStorageManager.getPlayingAppKoreanName());
	console.log("record : " + sessionStorageManager.getRecord());
	console.log("appHighestRecord : " + sessionStorageManager.getAppHighestRecord());
	console.log("writingID : " + sessionStorageManager.getWritingID());
	console.log("appGroup : " + sessionStorageManager.getAppGroup());
	console.log("language : " + sessionStorageManager.getLanguage());
}

function isLogin() {
	var filename = location.pathname.substring(location.pathname.lastIndexOf("/") + 1);

	if(filename === "login.html")
		return true;
	else if(filename === "license_timer.html")
		return true;

	return false;
}

function goLogin() {
	location.href = "login.html";
}

function isTypingGameApp() {
	if(sessionStorageManager.getPlayingAppName() == null)
		return false;

	if(sessionStorageManager.getPlayingAppID === 200)
		return true;

	if(sessionStorageManager.getPlayingAppID < 50 || sessionStorageManager.getPlayingAppID > 100)
		return false;

	return true;
}


function isMouseGameApp() {
	if(sessionStorageManager.getPlayingAppName() == null)
		return false;

	if(sessionStorageManager.getPlayingAppID > 100)
		return true;

	return false;
}


function isTypingPracticeApp() {
	if(sessionStorageManager.getPlayingAppName().indexOf("practice_") > -1)
		return true;

	return false;
}

function isTypingTestApp() {
	if(sessionStorageManager.getPlayingAppName().indexOf("test_") > -1)
		return true;

	return false;
}

function isTypingExamApp() {
	if(sessionStorageManager.getPlayingAppName() == "typing_exam")
		return true;

	return false;
}

function isEnglishTypingApp() {
	if(sessionStorageManager.getPlayingAppName().indexOf("english") > -1)
		return true;

	return false;
}

function isKoreanTypingApp() {
	if(sessionStorageManager.getPlayingAppName().indexOf("korean") > -1)
		return true;

	return false;
}

function isTypingWordApp() {
	var appName = sessionStorageManager.getPlayingAppName();

	if(appName.indexOf("_word") > -1)
		return true;

	// if((isTypingPracticeApp() || isTypingTestApp()) && appName.indexOf("_word") > -1)
	// 	return true;

	return false;
}

function isTypingSentenceApp() {
	var appName = sessionStorageManager.getPlayingAppName();

	if(appName.indexOf("_sentence") > -1)
		return true;

	// if((isTypingPracticeApp() || isTypingTestApp()) && appName.indexOf("_sentence") > -1)
	// 	return true;

	return false;
}

function isExperiencePlayerAccount() {
	if(sessionStorageManager.getMaestroAccountType() == 100)
		return true;

	return false;
}

function isExperienceMaestroAccount() {
	if(sessionStorageManager.getMaestroAccountType() == 101)
		return true;

	return false;
}


function getGameAppName() {
	var appName = sessionStorageManager.getPlayingAppName();

	if(isTypingPracticeApp())
		return "typing_practice";
	else if(isTypingTestApp())
		return "typing_test";
	else if(isTypingGameApp()) {
		if(isKoreanTypingApp())
			return appName.substring("typing_korean_".length);
		else if(isEnglishTypingApp())
			return appName.substring("typing_english_".length);
	}

	return appName;
}


var textStyleBasic = { font: "bold 32px Arial", fill: "#fff", align: "center", boundsAlignH: "center", boundsAlignV: "middle" };
