-- private variables
local background
local clientVersionLabel

-- public functions
function init()
  background = g_ui.displayUI('background')
  background:lower()

  clientVersionLabel = background:getChildById('clientVersionLabel')
  clientVersionLabel:setText('Nexdus  8.60\nnexdus.net')

  local logo = background:getChildById('logo')
  if logo then
    logo:show()
    logo:setOpacity(0)
  end

  if not g_game.isOnline() then
    addEvent(function()
      if logo then
        g_effects.fadeIn(logo, 1800)
      end
      g_effects.fadeIn(clientVersionLabel, 1800)
    end)
  end

  connect(g_game, { onGameStart = hide })
  connect(g_game, { onGameEnd = show })
end

function terminate()
  disconnect(g_game, { onGameStart = hide })
  disconnect(g_game, { onGameEnd = show })

  g_effects.cancelFade(background:getChildById('clientVersionLabel'))
  local logo = background:getChildById('logo')
  if logo then
    g_effects.cancelFade(logo)
  end
  background:destroy()

  Background = nil
end

function hide()
  background:hide()
end

function show()
  background:show()
end

function hideVersionLabel()
  background:getChildById('clientVersionLabel'):hide()
end

function setVersionText(text)
  clientVersionLabel:setText(text)
end

function getBackground()
  return background
end
