var txtName:String = "What is your name?"; 
var hideTexbox:boolean = true;
var hidePlayBox:boolean = false;
var hideIntroduction:boolean = false;
var hideMenu:boolean = true;

var itemTexture : Texture2D; 
var menuTexture : Texture2D; 
var menuStyle:GUIStyle;
var menuHeaderStyle:GUIStyle;

var count=0;

var sqlClass:sqlClass;
var namesList = Array();

var introStyle:GUIStyle;

function Start () {
	showIntro();
	hideTexbox = true;	
	sqlClass = new sqlClass();
	namesList = sqlClass.createDataBase();
}

function Update () {

}

function showIntro(){
	hideIntroduction = false;
	yield WaitForSeconds(3);
	hideIntroduction = true;
}

function loadHighScores(){
	count = 0;
	var widthName = 120;
	var widthScore = 250;
	var height = 120;
	for(name in namesList){
		count++;		
		GUI.Label(Rect(widthName, height+(40*count),100, 100),name[0], menuStyle);
		GUI.Label(Rect(widthScore, height+(40*count),100, 100),name[1], menuStyle);
		if(count>=10){
			count=0;
			widthName+=(250+30);
			widthScore+=(250+(100+30));
		}
	}
}

function OnGUI(){
	if(hideIntroduction){
		GUI.Label(Rect((Screen.width/2)-150, 30, 300, 60), 'ARKADOID', introStyle);
		GUI.DrawTexture (Rect(50, 50, (Screen.width-100), (Screen.height-100)), itemTexture);
		if(!hideTexbox){
			var menu:mainMenuController;
			menu = GameObject.FindGameObjectWithTag('menuSetting').GetComponent(mainMenuController);
			
			var player = menu.player;
			
			if(mainMenuController.gameOver==true){
				txtName = player.getName();
			}
			
			txtName = GUI.TextField(Rect((Screen.width/2)-75, (Screen.height/2)-15, 150, 30), txtName, 100);
			
			if(GUI.Button(Rect((Screen.width/2)-50, (Screen.height/2)+65,100,100), 'Start')){
			
				var menuC: mainMenuController;
				menuC = GameObject.FindGameObjectWithTag('menuSetting').GetComponent(mainMenuController);			
				
				sqlClass.addNewPlayer(txtName);
				hideTexbox = true;
				hideMenu = true;
				hidePlayBox = true;
				
				menuC.playerDetails(txtName);
				
				Application.LoadLevel(1);
			}
		}
		else if(!hideMenu){//Show high score
			//GUI.depth = 0;
    		GUI.DrawTexture (Rect(100, 100, (Screen.width-150), (Screen.height-150)), menuTexture);
    		GUI.Label(Rect(120, 120, 120, 50), 'Top High Scores', menuHeaderStyle);
    		loadHighScores();
    		
    		//Close button
    		if(GUI.Button(Rect(((Screen.width-80)), 100, 30, 30),  'X')){
    			//Hide Menu
    			hidePlayBox = false;
				hideTexbox = true;
				hideMenu = true;
    		}
		}
		
		if(!hidePlayBox){
			if(GUI.Button(Rect((Screen.width/2)-150, (Screen.height/2)-50,100,100), 'Play the game')){
				if(hideTexbox){
					hideTexbox = false;				
					hidePlayBox = true;
					hideMenu = false;
				}else{
					hidePlayBox = false;
					hideTexbox = true;
					hideMenu = false;
					txtName= '';
				}
			}
			
			if(GUI.Button(Rect((Screen.width/2)+30, (Screen.height/2)-50,130,100), 'View High Scores')){
				if(hideMenu){
					hideMenu = false;
					hideTextbox = true;
					hidePlayBox = true;
				}
			}
		}
	}else{
		GUI.Label(Rect((Screen.width/2)-150, ((Screen.height/2)-30), 300, 60), 'ARKADOID', introStyle);
	}
}