-- GLOBAL
Global( "wtMessage", nil )

--EVENT_SECOND_TIMER
function OnEventTimer( params )
local myrrhId = avatar.GetCurrencyId( "myrrh" )
if myrrhId then
  local info = avatar.GetCurrencyInfo( myrrhId )
  if info then
    local currentValue = info.value
	if (currentValue < 2000) then
		wtMessage:SetVal( "myrmyr", common.FormatInt( currentValue, "%dK6" ) )
		wtMessage:SetVal( "myrmyr1", common.GetEmptyWString() )
		wtMessage:SetVal( "myrmyr2", common.GetEmptyWString() )
		end
	if (currentValue >= 2000) and (currentValue <= 9999) then
		wtMessage:SetVal( "myrmyr1", common.FormatInt( currentValue, "%dK6" ) )
		wtMessage:SetVal( "myrmyr", common.GetEmptyWString() )
		wtMessage:SetVal( "myrmyr2", common.GetEmptyWString() )
		end
	if (currentValue > 9999) then
		wtMessage:SetVal( "myrmyr2", common.FormatInt( currentValue, "%dK6" ) )
		wtMessage:SetVal( "myrmyr1", common.GetEmptyWString() )
		wtMessage:SetVal( "myrmyr", common.GetEmptyWString() )
		end
  end
end
end


function OnAvatarCreated()
	common.RegisterEventHandler( OnEventTimer, "EVENT_SECOND_TIMER" )
end

--------------------------------------------------------------------------------

--| "SCRIPT_TOGGLE_UI" |--
function OnToggleUI( params )
	mainForm:Show( params.visible )
end

--| "U_EVENT_ADDON_MEM_USAGE_REQUEST" |--
function OnAMMemUsageRequest()
	userMods.SendEvent( "U_EVENT_ADDON_MEM_USAGE_RESPONSE", { sender = common.GetAddonName(), memUsage = gcinfo() } )
end

--------------------------------------------------------------------------------

-- INITIALIZATION
function Init()
	common.RegisterEventHandler(OnAvatarCreated,"EVENT_AVATAR_CREATED")
	if avatar.IsExist() then OnAvatarCreated() end
	
	common.RegisterEventHandler( OnToggleUI, "SCRIPT_TOGGLE_UI" )
	common.RegisterEventHandler( OnAMMemUsageRequest, "U_EVENT_ADDON_MEM_USAGE_REQUEST" )
		
	wtMessage = mainForm:GetChildChecked( "Announce", false )
	wtMessage:Show( true )
end
--------
Init()
--------