dofile("scripts/entities/entityinclude.lua")
dofile(appendUserDataPath("_mods/jukebox/scripts/jukeboxinclude.lua"))

--[[
Button layout on screen:

         RAND
 *PREV*         NEXT 
  
                     EXIT
--]]

local navmap = {
    [ACTION_MENUUP] = "jukebox-random",
    [ACTION_MENURIGHT] = "jukebox-next",
    [ACTION_MENUDOWN] = "jukebox-quit"
}

function init(me)
    jukebox_initButton(me)
end

function action(me, action, state)
	if isNestedMain() then return end
    return jukebox_doButtonAction(me, action, state, navmap)
end

function activate(me)
	if isNestedMain() then return end
	
	--playSfx("TitleAction")
	spawnParticleEffect("TitleEffect1", node_x(me), node_y(me))
	watch(0.5)
	
    local n = jukebox_getSong()
    if n > 1 then n = n - 1 else n = #SONG_LIST end
    jukebox_playSong(n)
end

function update(me, dt)
end
