content: ' ********** Copyright 2016 Roku Corp.  All Rights Reserved. **********
  
  ' Called when the HeroScreen component is initialized
  sub Init()
    'Get references to child nodes
    m.RowList       =   m.top.findNode("RowList")
    m.background    =   m.top.findNode("Background")
  
    m.HomescreenBuilder = CreateObject("roSGNode", "HomescreenBuilder")
    m.HomescreenBuilder.observeField("content", "onHomescreenBuilderContentChanged")
  
    'Create observer events for when content is loaded
    m.top.observeField("visible", "onVisibleChange")
    m.top.observeField("focusedChild", "OnFocusedChildChange")
  end sub
  
  ' observer function to handle when content loads
  sub onHomescreenBuilderContentChanged()
    print "HeroScreen.brs - [onHomescreenBuilderContentChanged]"
    m.top.content = m.HomescreenBuilder.content
  end sub
  
  ' handler of focused item in RowList
  sub OnItemFocused()
    'print "HeroScreen.brs - [onItemFocused]"
    itemFocused = m.top.itemFocused
  
    'When an item gains the key focus, set to a 2-element array,
    'where element 0 contains the index of the focused row,
    'and element 1 contains the index of the focused item in that row.
    if itemFocused.Count() = 2 then
      focusedContent            = m.top.content.getChild(itemFocused[0]).getChild(itemFocused[1])
      if focusedContent <> invalid then
        m.top.focusedContent    = focusedContent
        m.background.uri        = focusedContent.hdBackgroundImageUrl
      end if
    end if
  end sub
  
  ' sets proper focus to RowList in case channel returns from Details Screen
  sub onVisibleChange()
    'print "HeroScreen.brs - [onVisibleChange]"
    if m.top.visible then m.rowList.setFocus(true)
  end sub
  
  ' set proper focus to RowList in case if return from Details Screen
  Sub onFocusedChildChange()
    'print "HeroScreen.brs - [onFocusedChildChange]"
    if m.top.isInFocusChain() and not m.rowList.hasFocus() then m.rowList.setFocus(true)
  End Sub
  