
if Option.Debug.GetInfo == true then UserInfo.AddVal("Option", 1) end

BG = Image.load("Game Resources/Backgrounds/CreateBG1.png")

-- Loading Options.
dofile("Configuration/Options.cfg")

local Select = {
		State = "Main",
		-- "Main", "Game", "Sounds", "Graphic", "Debug"
		Index = 1,
		
		Game = {
			Index = 1,
			
			ScrollSpeed = nil, -- Integer (5 - 12)
			CursorSpeed = nil, -- CheckBox (1 - 2 - 3 - 4 - 5)
		},
		Sounds = {
			Index = 1,
			
			Switch = nil,
			Nature = nil,
			Buildings = nil,
			Units = nil,
		},
		Graphics = {
			Index = 1,
			
			AlphaPanel = false,
			NoUnitAnimate = false,
		},
		Debug = {
			Index = 1,
			
			ShowFPS = true,
			ShowObjID = true,
			GetInfo = true,
			DebugText = false,
			-- Objects Shown
			-- Objects Exists
			-- Center Coord (X,Y)
			
		},
}


ETi = 15
ExtTi = ETi


Select.Game.ScrollSpeed = Option.Game.ScrollSpeed
Select.Game.CursorSpeed = Option.Game.CursorSpeed

Select.Sounds.Switch = Option.Sounds.Switch
Select.Sounds.Nature = Option.Sounds.Nature
Select.Sounds.Buildings = Option.Sounds.Buildings
Select.Sounds.Units = Option.Sounds.Unit

Select.Graphics.AlphaPanel = Option.Graphics.AlphaPanel

Select.Debug.ShowFPS = Option.Debug.ShowFPS
Select.Debug.ShowObjID = Option.Debug.ShowObjID
Select.Debug.GetInfo = Option.Debug.GetInfo
Select.Debug.DebugText = Option.Debug.DebugText

local CheckBox = {
	a = {
		-- Radio head
		ON = Image.load("Game Resources/Backgrounds/CheckBoxON.png"),
		OFF = Image.load("Game Resources/Backgrounds/CheckBoxOFF.png"),
	},
	b = {
		-- CheckBox
		ON = Image.load("Game Resources/Backgrounds/CheckBox2ON.png"),
		OFF = Image.load("Game Resources/Backgrounds/CheckBox2OFF.png"),
	}
}

-- Copy-paste Text
--[[
Select.Debug.ShowFPS
Select.Debug.ShowObjID
Select.Debug.GetInfo
Select.Debug.DebugText
--]]

function SaveOptions(ScrollSpd, CursorSpd, Naturee, Build, Uni, SndSwitch, AlphaPan, AnimateUnit, ShowF, ShowObID, GetInf, DebugTxt)
	if Naturee == true then Naturee = "true" else Naturee = "false" end
	if Build == true then Build = "true" else Build = "false" end
	if Uni == true then Uni = "true" else Uni = "false" end
	if SndSwitch == true then SndSwitch = "true" else SndSwitch = "false" end
	
	if AlphaPan == true then AlphaPan = "true" else AlphaPan = "false" end
	if AnimateUnit == true then AnimateUnit = "true" else AnimateUnit = "false" end
	
	if ShowF == true then ShowF = "true" else ShowF = "false" end
	if ShowObID == true then ShowObID = "true" else ShowObID = "false" end
	if GetInf == true then GetInf = "true" else GetInf = "false" end
	if DebugTxt == true then DebugTxt = "true" else DebugTxt = "false" end
	
	OptionSave = io.open("Configuration/Options.cfg","w")
	OptionSave:write("Option = {\n")
	OptionSave:write("	Game = {\n")
	OptionSave:write("		CursorSpeed = "..CursorSpd..",\n")
					-- 1 = Slow, 2 = Normal, 3 = High
	OptionSave:write("		ScrollSpeed = "..ScrollSpd.."\n")
					-- Speed By Pixel
	OptionSave:write("	},\n")
	OptionSave:write("	Sounds = {\n")
	OptionSave:write("		Nature = "..Naturee..",\n")
	OptionSave:write("		Buildings = "..Build..",\n")
	OptionSave:write("		Unit = "..Uni..",\n")
	OptionSave:write("		\n")
	OptionSave:write("		Switch = "..SndSwitch..",\n")
	OptionSave:write("		\n")
	OptionSave:write("		Music = false,\n")
	OptionSave:write("		Volume = 100\n")
	OptionSave:write("	},\n")
	OptionSave:write("	Graphics = {\n")
	OptionSave:write("		AlphaPanel = "..AlphaPan..",\n")
	OptionSave:write("		NoUnitAnimate = "..AnimateUnit.."\n")
	OptionSave:write("	},\n")
	OptionSave:write("	Debug = {\n")
	OptionSave:write("		ShowFPS = "..ShowF..",\n")
	OptionSave:write("		ShowObjID = "..ShowObID..",\n")
	OptionSave:write("		GetInfo = "..GetInf..",\n")
	OptionSave:write("		DebugText = "..DebugTxt..",\n")
	OptionSave:write("		ShowTiles = false\n")
	OptionSave:write("	}\n")
	OptionSave:write("}")
	OptionSave:close()
end

VarPic = {
	Sounds = {
		x1 = 50,
		x2 = 68,
		
		y1 = 65,
		y2 = 105,
		y3 = 135,
		y4 = 165,
	},
}

while true do
	pad = Controls.read()
	screen:clear()
	
	screen:blit(0,0,BG)
	
	
	DrawShadowString(Arial, 210, 20, "Options", White)
	
	
	-- Main Options Menu
	if Select.State == "Main" then
		if pad:cross() then
			if Select.Index == 1 then
				Select.State = "Game"
				ExtTi = ETi
			end
			if Select.Index == 2 then
				Select.State = "Sounds"
				ExtTi = ETi
			end
			if Select.Index == 3 then
				Select.State = "Graphic"
				ExtTi = ETi
			end
			if Select.Index == 4 then
				Select.State = "Debug"
				ExtTi = ETi
			end
		end
		
		screen:fontPrint(Arial,50-1,67+1, "Game Options",Black)
		screen:fontPrint(Arial,50-1,107+1,"Audio Options",Black)
		screen:fontPrint(Arial,50-1,147+1,"Graphic Options",Black)
		screen:fontPrint(Arial,50-1,187+1,"Debug Options",Black)
		
		if Select.Index == 1 then 
			screen:fontPrint(Arial,50,67, "Game Options",Yellow)
			screen:fontPrint(Arial,50,107,"Audio Options",White)
			screen:fontPrint(Arial,50,147,"Graphic Options",White)
			screen:fontPrint(Arial,50,187,"Debug Options",White)
		elseif Select.Index == 2 then
			screen:fontPrint(Arial,50,67,"Game Options",White)
			screen:fontPrint(Arial,50,107,"Audio Options",Yellow)
			screen:fontPrint(Arial,50,147,"Graphic Options",White)
			screen:fontPrint(Arial,50,187,"Debug Options",White)
		elseif Select.Index == 3 then
			screen:fontPrint(Arial,50,67,"Game Options",White)
			screen:fontPrint(Arial,50,107,"Audio Options",White)
			screen:fontPrint(Arial,50,147,"Graphic Options",Yellow)
			screen:fontPrint(Arial,50,187,"Debug Options",White)
		elseif Select.Index == 4 then
			screen:fontPrint(Arial,50,67,"Game Options",White)
			screen:fontPrint(Arial,50,107,"Audio Options",White)
			screen:fontPrint(Arial,50,147,"Graphic Options",White)
			screen:fontPrint(Arial,50,187,"Debug Options",Yellow)
		end
	end
	
	----------------------------------------------------------- GAME ------------------------------------------------
	
	if Select.State == "Game" then
		screen:blit(150, 60, CheckBox.a.OFF)
		screen:blit(170, 60, CheckBox.a.OFF)
		screen:blit(190, 60, CheckBox.a.OFF)
		screen:blit(210, 60, CheckBox.a.OFF)
		screen:blit(230, 60, CheckBox.a.OFF)
		
		if Select.Game.CursorSpeed == 1 then
			Option.Game.CursorSpeed = 1
			screen:blit(150, 60, CheckBox.a.ON)
			--
			--
		elseif Select.Game.CursorSpeed == 2 then
			Option.Game.CursorSpeed = 2
			--
			screen:blit(170, 60, CheckBox.a.ON)
			--
		elseif Select.Game.CursorSpeed == 3 then
			Option.Game.CursorSpeed = 3
			--
			--
			screen:blit(190, 60, CheckBox.a.ON)
		elseif Select.Game.CursorSpeed == 4 then
			Option.Game.CursorSpeed = 4
			--
			--
			screen:blit(210, 60, CheckBox.a.ON)
		elseif Select.Game.CursorSpeed == 5 then
			Option.Game.CursorSpeed = 5
			--
			--
			screen:blit(230, 60, CheckBox.a.ON)
		end
		
		screen:fontPrint(Arial,50-1,72+1,"Cursor Speed", Black)
		DrawShadowString(Arial, 260, 72, Select.Game.CursorSpeed.." / 5", White)
		
		-- Slow
		if Select.Game.CursorSpeed == 1 or Select.Game.CursorSpeed == 2 then
			DrawShadowString(Arial, 298, 72, "Slow", White)
		end
		
		-- Normal
		if Select.Game.CursorSpeed == 3 then
			DrawShadowString(Arial, 298, 72, "Normal", White)
		end
		
		-- Fast
		if Select.Game.CursorSpeed == 4 or Select.Game.CursorSpeed == 5 then
			DrawShadowString(Arial, 298, 72, "Fast", White)
		end
		
		
		screen:fontPrint(Arial,50-1,107+1,"Scroll Speed", Black)
		screen:fontPrint(Arial,155 - 1,107 + 1,"Pixels: "..Select.Game.ScrollSpeed, Black)
		screen:fontPrint(Arial,155,107,"Pixels: "..Select.Game.ScrollSpeed, White)
		
		if Select.Game.Index == 1 then
			screen:fontPrint(Arial,50,72,"Cursor Speed", White)
			screen:fontPrint(Arial,50,107,"Scroll Speed", Yellow)
		elseif Select.Game.Index  == 2 then
			screen:fontPrint(Arial,50,72,"Cursor Speed", Yellow)
			screen:fontPrint(Arial,50,107,"Scroll Speed", White)
		end
		
	end
	
	----------------------------------------------------------- SOUNDS ------------------------------------------------
	
	if Select.State == "Sounds" then
		
		screen:blit(VarPic.Sounds.x2 + 125, VarPic.Sounds.y1-12, CheckBox.b.OFF)
		screen:blit(VarPic.Sounds.x2 + 125, VarPic.Sounds.y2-12, CheckBox.b.OFF)
		screen:blit(VarPic.Sounds.x2 + 125, VarPic.Sounds.y3-12, CheckBox.b.OFF)
		screen:blit(VarPic.Sounds.x2 + 125, VarPic.Sounds.y4-12, CheckBox.b.OFF)
		
		if Select.Sounds.Switch == true then
			Option.Sounds.Switch = true
			screen:blit(VarPic.Sounds.x2 + 125, VarPic.Sounds.y1-12, CheckBox.b.ON)
		else
			Option.Sounds.Switch = false
		end
		if Select.Sounds.Nature == true then
			Option.Sounds.Nature = true
			screen:blit(VarPic.Sounds.x2 + 125, VarPic.Sounds.y2-12, CheckBox.b.ON)
		else
			Option.Sounds.Nature = false
		end
		if Select.Sounds.Buildings == true then
			Option.Sounds.Buildings = true
			screen:blit(VarPic.Sounds.x2 + 125, VarPic.Sounds.y3-12, CheckBox.b.ON)
		else
			Option.Sounds.Buildings = false
		end
		if Select.Sounds.Units == true then
			Option.Sounds.Unit = true
			screen:blit(VarPic.Sounds.x2 + 125, VarPic.Sounds.y4-12, CheckBox.b.ON)
		else
			Option.Sounds.Unit = false
		end
		screen:fontPrint(Arial,VarPic.Sounds.x1-1,VarPic.Sounds.y1+1,"Enable Sounds",Black)
		screen:fontPrint(Arial,VarPic.Sounds.x2-1,VarPic.Sounds.y2+1,"Nature Sounds",Black)
		screen:fontPrint(Arial,VarPic.Sounds.x2-1,VarPic.Sounds.y3+1,"Buildings Sounds",Black)
		screen:fontPrint(Arial,VarPic.Sounds.x2-1,VarPic.Sounds.y4+1,"Unit Sounds",Black)
		if Select.Sounds.Index == 1 then
			screen:fontPrint(Arial,VarPic.Sounds.x1,VarPic.Sounds.y1,"Enable Sounds",yellow)
			screen:fontPrint(Arial,VarPic.Sounds.x2,VarPic.Sounds.y2,"Nature Sounds",white)
			screen:fontPrint(Arial,VarPic.Sounds.x2,VarPic.Sounds.y3,"Buildings Sounds",white)
			screen:fontPrint(Arial,VarPic.Sounds.x2,VarPic.Sounds.y4,"Unit Sounds",white)
		elseif Select.Sounds.Index  == 2 then
			screen:fontPrint(Arial,VarPic.Sounds.x1,VarPic.Sounds.y1,"Enable Sounds",white)
			screen:fontPrint(Arial,VarPic.Sounds.x2,VarPic.Sounds.y2,"Nature Sounds",yellow)
			screen:fontPrint(Arial,VarPic.Sounds.x2,VarPic.Sounds.y3,"Buildings Sounds",white)
			screen:fontPrint(Arial,VarPic.Sounds.x2,VarPic.Sounds.y4,"Unit Sounds",white)
		elseif Select.Sounds.Index == 3 then
			screen:fontPrint(Arial,VarPic.Sounds.x1,VarPic.Sounds.y1,"Enable Sounds",white)
			screen:fontPrint(Arial,VarPic.Sounds.x2,VarPic.Sounds.y2,"Nature Sounds",white)
			screen:fontPrint(Arial,VarPic.Sounds.x2,VarPic.Sounds.y3,"Buildings Sounds",yellow)
			screen:fontPrint(Arial,VarPic.Sounds.x2,VarPic.Sounds.y4,"Unit Sounds",white)
		elseif Select.Sounds.Index == 4 then
			screen:fontPrint(Arial,VarPic.Sounds.x1,VarPic.Sounds.y1,"Enable Sounds",white)
			screen:fontPrint(Arial,VarPic.Sounds.x2,VarPic.Sounds.y2,"Nature Sounds",white)
			screen:fontPrint(Arial,VarPic.Sounds.x2,VarPic.Sounds.y3,"Buildings Sounds",white)
			screen:fontPrint(Arial,VarPic.Sounds.x2,VarPic.Sounds.y4,"Unit Sounds",yellow)
		end
		
		-- DEBUG ONLY
		--[[
		if Select.Sounds.Switch == true then
			screen:fontPrint(Arial,VarPic.Sounds.x1+210+50,VarPic.Sounds.y1+1,"ES = true",Black)
		else
			screen:fontPrint(Arial,VarPic.Sounds.x1+210,VarPic.Sounds.y1+1,"ES = false",Black)
		end
		
		if Select.Sounds.Nature == true then
			screen:fontPrint(Arial,VarPic.Sounds.x2+210,VarPic.Sounds.y2+1,"NS = true",Black)
		else
			screen:fontPrint(Arial,VarPic.Sounds.x2+210,VarPic.Sounds.y2+1,"NS = false",Black)
		end
		
		if Select.Sounds.Buildings == true then
			screen:fontPrint(Arial,VarPic.Sounds.x2+210,VarPic.Sounds.y3+1,"BS = true",Black)
		else
			screen:fontPrint(Arial,VarPic.Sounds.x2+210,VarPic.Sounds.y3+1,"BS = false",Black)
		end
		
		if Select.Sounds.Units == true then
			screen:fontPrint(Arial,VarPic.Sounds.x2+210,VarPic.Sounds.y4+1,"US = true",Black)
		else
			screen:fontPrint(Arial,VarPic.Sounds.x2+210,VarPic.Sounds.y4+1,"US = false",Black)
		end
		
		
		
		
		
		if Option.Sounds.Switch == true then
			screen:fontPrint(Arial,VarPic.Sounds.x1+280+50,VarPic.Sounds.y1+1,"ESo = true",Black)
		else
			screen:fontPrint(Arial,VarPic.Sounds.x1+280,VarPic.Sounds.y1+1,"ESo = false",Black)
		end
		
		if Option.Sounds.Nature == true then
			screen:fontPrint(Arial,VarPic.Sounds.x2+280,VarPic.Sounds.y2+1,"NSo = true",Black)
		else
			screen:fontPrint(Arial,VarPic.Sounds.x2+280,VarPic.Sounds.y2+1,"NSo = false",Black)
		end
		
		if Option.Sounds.Buildings == true then
			screen:fontPrint(Arial,VarPic.Sounds.x2+280,VarPic.Sounds.y3+1,"BSo = true",Black)
		else
			screen:fontPrint(Arial,VarPic.Sounds.x2+280,VarPic.Sounds.y3+1,"BSo = false",Black)
		end
		
		if Option.Sounds.Unit == true then
			screen:fontPrint(Arial,VarPic.Sounds.x2+280,VarPic.Sounds.y4+1,"USo = true",Black)
		else
			screen:fontPrint(Arial,VarPic.Sounds.x2+280,VarPic.Sounds.y4+1,"USo = false",Black)
		end
		
		screen:fontPrint(Arial,VarPic.Sounds.x2+210,VarPic.Sounds.y4+40,"SndIndex = "..Select.Sounds.Index,Black)
		--]]
		
	end 
	
	----------------------------------------------------------- GRAPHICS ------------------------------------------------
	
	if Select.State == "Graphic" then
		
		screen:fontPrint(Arial,50-1,72+1,"Transparent Panel",Black)
		
		
		if Select.Graphics.Index == 1 then
			screen:fontPrint(Arial,50,72,"Transparent Panel",Yellow)
		elseif Select.Graphics.Index == 2 then
			screen:fontPrint(Arial,50,72,"Transparent Panel",White)
		else
			screen:fontPrint(Arial,50,72,"Transparent Panel",White)
		end
		
		if Select.Graphics.AlphaPanel == true then
			screen:blit(200, 60, CheckBox.a.ON)
		else
			screen:blit(200, 60, CheckBox.a.OFF)
		end
		
		
		
	end

	----------------------------------------------------------- DEBUG ------------------------------------------------
	
	if Select.State == "Debug" then
		
		screen:fontPrint(Arial,50-1,72+1,"Show FPS",Black)
		screen:fontPrint(Arial,50-1,72+35+1,"Show Object's ID",Black)
		screen:fontPrint(Arial,50-1,72+35+35+1,"Allow Gathering Actions Info",Black)
		screen:fontPrint(Arial,50-1,72+35+35+35+1,"Show Debug Info",Black)
		
		if Select.Debug.Index == 1 then
			screen:fontPrint(Arial,50,72,"Show FPS",Yellow)
			screen:fontPrint(Arial,50,72+35,"Show Object's ID",White)
			screen:fontPrint(Arial,50,72+35+35,"Allow Gathering Actions Info",White)
			screen:fontPrint(Arial,50,72+35+35+35,"Show Debug Info",White)
		elseif Select.Debug.Index == 2 then
			screen:fontPrint(Arial,50,72,"Show FPS",White)
			screen:fontPrint(Arial,50,72+35,"Show Object's ID",Yellow)
			screen:fontPrint(Arial,50,72+35+35,"Allow Gathering Actions Info",White)
			screen:fontPrint(Arial,50,72+35+35+35,"Show Debug Info",White)
		elseif Select.Debug.Index == 3 then
			screen:fontPrint(Arial,50,72,"Show FPS",White)
			screen:fontPrint(Arial,50,72+35,"Show Object's ID",White)
			screen:fontPrint(Arial,50,72+35+35,"Allow Gathering Actions Info",Yellow)
			screen:fontPrint(Arial,50,72+35+35+35,"Show Debug Info",White)
		elseif Select.Debug.Index == 4 then
			screen:fontPrint(Arial,50,72,"Show FPS",White)
			screen:fontPrint(Arial,50,72+35,"Show Object's ID",White)
			screen:fontPrint(Arial,50,72+35+35,"Allow Gathering Actions Info",White)
			screen:fontPrint(Arial,50,72+35+35+35,"Show Debug Info",Yellow)
		end
		
		screen:blit(300, 60, CheckBox.a.OFF)
		screen:blit(300, 60+35, CheckBox.a.OFF)
		screen:blit(300, 60+35+35, CheckBox.a.OFF)
		screen:blit(300, 60+35+35+35, CheckBox.a.OFF)
		
		if Select.Debug.ShowFPS == true then
			screen:blit(300, 60, CheckBox.a.ON)
		end
		if Select.Debug.ShowObjID == true then
			screen:blit(300, 60+35, CheckBox.a.ON)
		end
		if Select.Debug.GetInfo == true then
			screen:blit(300, 60+35+35, CheckBox.a.ON)
		end
		if Select.Debug.DebugText == true then
			screen:blit(300, 60+35+35+35, CheckBox.a.ON)
		end
		
	end
	
	
	
	--[[
	if pad:triangle() then
		Select.Sounds.Switch = true
		Select.Sounds.Nature = true
		Select.Sounds.Buildings = true
		Select.Sounds.Units =  true
	end
	
	if pad:square() then
		Select.Sounds.Switch = false
		Select.Sounds.Nature = false
		Select.Sounds.Buildings = false
		Select.Sounds.Units =  false
	end
	--]]
	
	ExtTi = ExtTi - 1
	if ExtTi < 0 then ExtTi = 0 end
	
	if pad:cross() and ExtTi == 0 then
		if pressed.cross == false then
			pressed.cross = true
			
			--------------------------------------------------------------------------------------------
			--------------------------------------------------------------------------------------------
			--------------------------------------------------------------------------------------------
			
			if Select.State == "Sounds" then
				
				if Select.Sounds.Index == 1 then
					if Select.Sounds.Switch == true then
						Select.Sounds.Switch = false
					else
						Select.Sounds.Switch = true
					end
				end
				
				if Select.Sounds.Index == 2 then
					if Select.Sounds.Nature == true then
						Select.Sounds.Nature = false
					else
						Select.Sounds.Nature = true
					end
				end
				
				if Select.Sounds.Index == 3 then
					if Select.Sounds.Buildings == true then
						Select.Sounds.Buildings = false
					else
						Select.Sounds.Buildings = true
					end
				end
				
				if Select.Sounds.Index == 4 then
					if Select.Sounds.Units == true then
						Select.Sounds.Units = false
					else
						Select.Sounds.Units = true
					end
				end
				
			end
			
			--------------------------------------------------------------------------------------------
			--------------------------------------------------------------------------------------------
			--------------------------------------------------------------------------------------------
			
			if Select.State == "Graphic" then
				if Select.Graphics.Index == 1 then
					if Select.Graphics.AlphaPanel == true then
						Select.Graphics.AlphaPanel = false
					else
						Select.Graphics.AlphaPanel = true
					end
				end
			end
			
			--------------------------------------------------------------------------------------------
			--------------------------------------------------------------------------------------------
			--------------------------------------------------------------------------------------------
			
			if Select.State == "Debug" then
				if Select.Debug.Index == 1 then
					if Select.Debug.ShowFPS == true then
						Select.Debug.ShowFPS = false
					else
						Select.Debug.ShowFPS = true
					end
				end
				
				if Select.Debug.Index == 2 then	
					if Select.Debug.ShowObjID == true then
						Select.Debug.ShowObjID = false
					else
						Select.Debug.ShowObjID = true
					end
				end
				
				if Select.Debug.Index == 3 then
					if Select.Debug.GetInfo == true then
						Select.Debug.GetInfo = false
					else
						Select.Debug.GetInfo = true
					end
				end
				
				if Select.Debug.Index == 4 then
					if Select.Debug.DebugText == true then
						Select.Debug.DebugText = false
					else
						Select.Debug.DebugText = true
					end
				end
				
			end
			
			--------------------------------------------------------------------------------------------
			--------------------------------------------------------------------------------------------
			--------------------------------------------------------------------------------------------
			
			
			ExtTi = ETi
		end
	else
		pressed.cross = false
	end
	
	
	
	if pad:up() then
		if pressed.up == false then
			pressed.up = true
			if Select.State == "Main" then
				Select.Index = Select.Index - 1
				if Select.Index  < 1 then Select.Index = 4 end
			elseif Select.State == "Game" then
				Select.Game.Index = Select.Game.Index - 1
				if Select.Game.Index < 1 then Select.Game.Index = 2 end
			elseif Select.State == "Sounds" then
				Select.Sounds.Index = Select.Sounds.Index - 1
				if Select.Sounds.Index < 1 then Select.Sounds.Index = 4 end
			elseif Select.State == "Graphic" then
				Select.Graphics.index = Select.Graphics.Index - 1
				if Select.Graphics.Index < 1 then Select.Graphics.Index = 2 end
			elseif Select.State == "Debug" then
				Select.Debug.Index = Select.Debug.Index - 1
				if Select.Debug.Index < 1 then Select.Debug.Index = 4 end
			end
			
		end
	else
		pressed.up = false
	end
		
	if pad:down() then 
		if pressed.down == false then
			pressed.down = true
			if Select.State == "Main" then
				Select.Index = Select.Index + 1
				if Select.Index > 4 then Select.Index = 1 end
			elseif Select.State == "Game" then
				Select.Game.Index = Select.Game.Index + 1
				if Select.Game.Index > 2 then Select.Game.Index = 1 end
			elseif Select.State == "Sounds" then
				Select.Sounds.Index = Select.Sounds.Index + 1
				if Select.Sounds.Index > 4 then Select.Sounds.Index = 1 end
			elseif Select.State == "Graphic" then
				Select.Graphics.index = Select.Graphics.Index + 1
				if Select.Graphics.Index > 2 then Select.Graphics.Index = 1 end
			elseif Select.State == "Debug" then
				Select.Debug.Index = Select.Debug.Index + 1
				if Select.Debug.Index > 4 then Select.Debug.Index = 1 end
			end
			
		end
	else
		pressed.down = false
	end
	
	if pad:left() then
		if pressed.left == false then
			pressed.left = true
			if Select.State == "Game" then
				if Select.Game.Index == 1 then
						if Select.Game.ScrollSpeed ~= 1 then Select.Game.ScrollSpeed = Select.Game.ScrollSpeed - 1 end
				elseif Select.Game.Index == 2 then
					if Select.Game.CursorSpeed ~= 1 then Select.Game.CursorSpeed = Select.Game.CursorSpeed - 1 end
				end
			end
		end
	else
		pressed.left = false
	end
	
	if pad:right() then
		if pressed.right == false then
			pressed.right = true
			if Select.State == "Game" then
				if Select.Game.Index == 1 then
					if Select.Game.ScrollSpeed ~= 12 then Select.Game.ScrollSpeed = Select.Game.ScrollSpeed + 1 end
				elseif Select.Game.Index == 2 then
					if Select.Game.CursorSpeed ~= 5 then Select.Game.CursorSpeed = Select.Game.CursorSpeed + 1 end
				end
			end
		end
	else
		pressed.right = false
	end
	
	if Select.State == "Game" or Select.State == "Sounds" or Select.State == "Graphic" or Select.State == "Debug" then
		if pad:circle() then
			if pressed.circle == false then
				pressed.circle = true
				Select.State = "Main"
			end
		else
			pressed.circle = false
		end
	end
	if Select.State == "Main" then
		if pad:circle() then
			if pressed.circle == false then
				pressed.circle = true
				SaveOptions(Option.Game.ScrollSpeed, Option.Game.CursorSpeed, Option.Sounds.Nature, Option.Sounds.Buildings, Option.Sounds.Unit, Option.Sounds.Switch, Select.Graphics.AlphaPanel, false, Select.Debug.ShowFPS, Select.Debug.ShowObjID, Select.Debug.GetInfo, Select.Debug.DebugText)
				ClearRAM("Options")
				dofile("MainMenu.lua")
			end
		else
			pressed.circle = false
		end
	end
	
	if pad:select() then
		Screenshot()
	end
	
	screen.waitVblankStart(1)
	screen.flip()
end
