
local CounterWnd = nil
local NameWnd = nil


function OnCreate()
  CounterWnd = self:FindChild("counter")
  NameWnd = self:FindChild("item_name")
end

function OnShow()
  SetTimerWidget(self:GetName(), "clock_anim")
end


function SetName(name)
  NameWnd:SetText(L10n:ExpandString(name))
end

function GetCounterWidget()
  return CounterWnd
end

function GetItemMidPos()
  pos = CounterWnd:GetAbsRelPos()
  size = CounterWnd:GetAbsRelSize()
  size.y = 0
  return  pos + size
end

function MenuButtonClick(_sender)
  if states["sys_block_esc"] == 0 then
    OpenMainMenu()
  end
end

function DiaryButtonClick(_sender)
  d = OpenDiary()
  d:SetVisible(true)
end

function SetSenderCaption(_sender)
  SetInterfaceCaption(L10n:ExpandString(_sender:GetCaption()))
end

function ResetCaption(_sender)
  SetInterfaceCaption("")
end

function PulitzerEnter()
  caption = L10n:ExpandString("sys_bonus_name").." "..tostring( states["ho_bonuses_count"] )
  SetInterfaceCaption(caption)
end

function HintClick(_sender)
    if CanTakeHintClue() then
        SetHintAnimOnZero()
        PlayHoHint(self:GetName(), _sender:GetName())
    end
end


function onDiaryLeave()
  self:FindChild("diary_btn"):SetVisible(true)
  self:FindChild("diary_anim"):SetVisible(false)
end
 
function onDiaryEnter(_sender)
  self:FindChild("diary_btn"):SetVisible(false)
  self:FindChild("diary_anim"):SetVisible(true)  
  AnimateWidget("ho_counter_list", "diary_anim", 0.5, 50)
  SetSenderCaption(_sender)
end
 
function onDiaryLeaveCaption()
  ResetCaption()
  onDiaryLeave()
end
