--Colors
yellow = Color.new(255,255,0)

--USBmode
DiskMode = false

--font
font = Font.load("font/BRITANIC.TTF")
font:setPixelSizes(15,20)

--Battery
battery0 = Image.load("IMG/battery/null.png")
battery1 = Image.load("IMG/battery/20.png") 
battery2 = Image.load("IMG/battery/40.png") 
battery3 = Image.load("IMG/battery/60.png") 
battery4 = Image.load("IMG/battery/80.png")
battery5 = Image.load("IMG/battery/full.png")

--background load
bg = Image.load("IMG/wall.png")

--selector
cursor = Image.load("IMG/cursor.png")
cursorx = 100
cursory = 55


--icons load
browser = Image.load("IMG/icons/browser.png")
credits = Image.load("IMG/icons/credits.png")
lua =  Image.load("IMG/icons/lua.png")
mp3 = Image.load("IMG/icons/mp3.png")
usb = Image.load("IMG/icons/usb.png")


--blocks for Icons

b ={
x = 90; y = 66; height = 60; width = 60; img = browser }

m ={
x = 170; y = 66; height = 60; width = 60; img = mp3}

l ={
x = 250; y = 66; height = 60; width = 60; img = lua }

c ={
x = 330; y = 66; height = 60; width = 60; img = credits }


Oldpad= Controls.read()
local lastkeyin = Controls.read()
--main Loop

while true do
Date = os.date ("!*t")
Date.hour = Date.hour - 2
if Date.hour == 12 then
Date.hour = 0
end
if Date.hour < 0 then
Date.hour = Date.hour + 12
end
if Date.hour > 12 then
Date.hour = Date.hour - 12
end
screen:clear()
keyin = Controls.read()
pad = Controls.read()

--selector usage

if pad:right() then
cursorx=cursorx+3
end
if pad:left() then
cursorx=cursorx-3
end
if pad:up() then
cursory=cursory-3
end

if pad:down() then
cursory=cursory+3
end

--collisions
if cursorx > 90 and cursorx < 150 and cursory>66 and cursory<106 then
if pad:cross() and not oldpad:cross() then
dofile("msbrowser.lua")
file:close()
end
end

if cursorx > 170 and cursorx < 230 and cursory>66 and cursory<106 then
if pad:cross() and not oldpad:cross() then
dofile("mp3.lua")
file:close()
end
end

if cursorx > 250 and cursorx < 310 and cursory>66 and cursory<106 then
if pad:cross() and not oldpad:cross() then
dofile("luabrowser.lua")
file:close()
end
end

if cursorx > 330 and cursorx < 400 and cursory>66 and cursory<106 then
if pad:cross() and not oldpad:cross() then
dofile("credits.lua")
file:close()
end
end




screen:blit(0,0,bg)


screen:blit(b.x,b.y,b.img)
screen:blit(l.x,l.y,l.img)
screen:blit(m.x,m.y,m.img)
screen:blit(c.x,c.y,c.img)

screen:blit(cursorx,cursory,cursor)

if keyin:l() then
      isDiskMode = true
      screen.waitVblankStart(40)
      while isDiskMode do
         System.usbDiskModeActivate()
		 screen:clear()
		 screen:blit(0,0,bg)
		 screen:blit(40,22,usb)
	 diskmodekey = Controls.read()
         isDiskMode = not diskmodekey:l()
         screen.waitVblankStart()
         screen:flip()
      end
	  System.usbDiskModeDeactivate()
	  screen:clear()
	  dofile("menu.lua")
      screen.waitVblankStart(40)
   end
   
  if System.powerGetBatteryLifePercent() >= 0 then batteryL = battery0 end
  if System.powerGetBatteryLifePercent() > 20 then batteryL = battery1 end
  if System.powerGetBatteryLifePercent() > 40 then batteryL = battery1 end
  if System.powerGetBatteryLifePercent() > 60 then batteryL = battery4 end
  if System.powerGetBatteryLifePercent() > 80 then batteryL = battery4 end
  if System.powerGetBatteryLifePercent() > 95 then batteryL = battery5 end

screen:blit(425,2,batteryL)
screen:fontPrint (font,10,15, ""..Date.hour..":"..Date.min, red)
screen:fontPrint(font,150,262, "Press L To Activate DiskMode", red)

oldpad = pad
screen.waitVblankStart()
screen.flip()
end
