


action["sys_ui_anim_back"] = function(r,c, parentName, name, maxFrame)
 
  if not UI:WidgetExists(parentName) then return end  
  animWidget = StaticImage( Widget(parentName):FindChild(name))
  if not animWidget:IsVisible() then return end
  local c  = animWidget:GetCurrentIndex() - 1
  if c == 0 then return end
  animWidget:SetItemIndex(c)
end


function AnimateWidgetBack(parentName, widgetName, time, framesCount, callback) 
  if not UI:WidgetExists(parentName) then return end
  
  local t     = (time * 1000)/framesCount
  local cmd=Cmd() 
  
  
  RemoveTask(parentName..widgetName.."_back")
  RemoveTask(parentName..widgetName)
  
  cmd:SetHolded(false)
  cmd:SetNotPersist()
  
  cmd:SetName(parentName..widgetName.."_back")
  
  --StaticImage( Widget(parentName):FindChild(widgetName)):SetItemIndex(framesCount)
  cmd(tSetState("sys_"..parentName..widgetName, 1))
  cmd( tAction("sys_ui_anim_back", parentName, widgetName,framesCount) )
  for i = 1,framesCount do
    cmd( tSleep(t) )
    cmd( tAction("sys_ui_anim_back", parentName, widgetName,framesCount) )
  end
  cmd(tSetState("sys_"..parentName..widgetName, 0))
  if callback then
    cmd(tAction(callback)) end
end

action["sys_ui_anim"] = function(r,c, parentName, name, maxFrame)
  if not UI:WidgetExists(parentName) then return end
  if states["sys_"..parentName..name] == 1 then return end
  animWidget = StaticImage( Widget(parentName):FindChild(name))
  if not animWidget:IsVisible() then return end
  local c  = animWidget:GetCurrentIndex() + 1  
  if c > maxFrame then return end
  animWidget:SetItemIndex(c)
end


function AnimateWidget(parentName, widgetName, time, framesCount) 
  if not UI:WidgetExists(parentName) then return end
  
  local t     = (time * 1000)/framesCount
  local cmd=Cmd() 
  
  RemoveTask(parentName..widgetName.."_back")
  RemoveTask(parentName..widgetName)
  
  cmd:SetHolded(false)
  cmd:SetNotPersist()
  --StaticImage( Widget(parentName):FindChild(widgetName)):SetItemIndex(0)
  cmd( tAction("sys_ui_anim", parentName, widgetName,framesCount) )
  cmd:SetName(parentName..widgetName)
  for i = 1,framesCount do
    cmd( tSleep(t) )
    cmd( tAction("sys_ui_anim", parentName, widgetName,framesCount) )
  end
end
 