local ABOUT_CLICKED = 0
local HOWTOPLAY_CLICKED = 1
local CLOSE_CLICKED = 0
local HOME_CLICKED = 0

function DoMenu()

        drawimage(IMGBACKGROUND, 0, 0)

        drawimage(IMGPANELCOVER, 0, 248)
        
        drawimage(IMGABOUTBUTTON, 15, 253, ABOUT_CLICKED*70, 0, ABOUT_CLICKED*70+70, imageheight(IMGABOUTBUTTON))
        
        drawimage(IMGHOWTOPLAY, 100, 259, HOWTOPLAY_CLICKED*70, 0, HOWTOPLAY_CLICKED*70+70, imageheight(IMGHOWTOPLAY))

        drawimage(IMGCLOSEBUTTON, 1, 300, CLOSE_CLICKED*19, 0, CLOSE_CLICKED*19+19, imageheight(IMGCLOSEBUTTON))

        drawimage(IMGHOMEBUTTON, 188, 273, HOME_CLICKED*40, 0, HOME_CLICKED*40+40, imageheight(IMGHOMEBUTTON))

        if HOWTOPLAY_CLICKED == 1 then
                drawimage(IMGHOWTOPLAYPANEL, 0, 12)
        end
        if ABOUT_CLICKED == 1 then
                drawimage(IMGABOUTPANEL, 0, 12)
        end


end -- DoMenu


function menu_onstylusup(x, y) 
        if HOME_CLICKED == 1 then
                if mousein(188, 273, 188+40, 273+imageheight(IMGHOMEBUTTON)) then
                        -- switch to game mode
                        CURRENT_STATE = STATE_PLAYING
                end
                HOME_CLICKED = 0

        elseif CLOSE_CLICKED == 1 then
                if mousein(1, 300, 1+19, 300+imageheight(IMGCLOSEBUTTON)) then
                        -- quit the game
                        quit()
                end
                CLOSE_CLICKED = 0
        end
end -- menu_onstylusup


function menu_onstylusdown(x, y)
        
        if mousein(15, 253, 15+70, 253+imageheight(IMGABOUTBUTTON)) then
                -- about button
                ABOUT_CLICKED = 1
                HOWTOPLAY_CLICKED = 0
                playsound(SNDHEAVYCLICK)
        
        elseif mousein(100, 259, 100+70, 259+imageheight(IMGHOWTOPLAY)) then
                -- how to play button
                HOWTOPLAY_CLICKED = 1
                ABOUT_CLICKED = 0
                playsound(SNDHEAVYCLICK)

        elseif mousein(188, 273, 188+40, 273+imageheight(IMGHOMEBUTTON)) then
                -- home button
                HOME_CLICKED = 1
                playsound(SNDHEAVYCLICK)

        elseif mousein(1, 300, 1+19, 300+imageheight(IMGCLOSEBUTTON)) then
                -- quit button
                CLOSE_CLICKED = 1
                playsound(SNDHEAVYCLICK)
        end
        
end -- menu_onstylusdown
