<?xml version="1.0" encoding="utf-8" ?>

<component name="PeliculaItemComponent" extends="Group" >

<!-- Note that target and rect are both set during the interpolation -->
<interface>
    <field id="index"       type="int" />
    <field id="groupHasFocus" type="boolean" onChange="focusPercentChanged"/>
    <field id="itemContent" type="node"   onChange="itemContentChanged" />
    <field id="currTarget"  type="float"  onChange="currTargetChanged" />
    <field id="currRect"    type="rect2d" onChange="currRectChanged" />
    <field id="focusPercent" type="float" onChange="focusPercentChanged" />
</interface>

<script type="text/brightscript" >
<![CDATA[
    function init()
        'm.theRect  = m.top.findNode("theRect")
        'm.theLabel = m.top.findNode("theLabel")
        'm.descLabel = m.top.findNode("descLabel")
        'm.starRatingRect = m.top.findNode("starRatingRect")
        'm.starRatingLabel = m.top.findNode("starRatingLabel")
        m.itemPoster = m.top.findNode("itemPoster")
        'm.focusColorInterp = m.top.findNode("focusColorInterp")
        'm.focusColorInterp.fieldToInterp = "theRect.color"
        'm.itemPoster.loadWidth       = 300
        'm.itemPoster.loadHeight      = 440
    end function

    function itemContentChanged()
        'm.theLabel.text = m.top.itemContent.title
        'm.descLabel.text = m.top.itemContent.Description
        'm.starRatingLabel.text = m.top.itemContent.StarRating.toStr() + "%"
        m.itemPoster.uri = m.top.itemContent.HDPosterUrl
        if m.top.currRect <> invalid then
            m.itemPoster.width       = m.top.currRect.width
            m.itemPoster.height       = m.top.currRect.height
        end if
    end function

    function currTargetChanged()
        'if m.top.index = 0
            ''print "currTarget for item "; m.top.index; " changed to "; m.top.currTarget
        'end if
    end function

    function currRectChanged()
        'if m.top.itemContent <> invalid then m.itemPoster.uri = m.top.itemContent.HDPosterUrl
        'm.theLabel.width       = m.top.currRect.width - 8
        'm.descLabel.width       = m.top.currRect.width - 8
        'm.theRect.width       = m.top.currRect.width
        'm.theRect.height      = m.top.currRect.height
        m.itemPoster.width       = m.top.currRect.width
        m.itemPoster.height       = m.top.currRect.width*440/300
        'm.descLabel.height      = m.top.currRect.height - m.itemPoster.height - 25
        'm.descLabel.translation = [4, m.top.currRect.height-m.descLabel.height+6]
        'm.starRatingRect.translation = [m.top.currRect.width-50, 25]
    end function

    function focusPercentChanged()
        'if m.top.itemContent <> invalid then m.itemPoster.uri = m.top.itemContent.HDPosterUrl
        if (m.top.groupHasFocus)
           ' m.focusColorInterp.fraction = m.top.focusPercent
            m.itemPoster.translation = [0, 35*m.top.focusPercent]
            'm.starRatingRect.opacity = m.top.focusPercent
        else
           ' m.focusColorInterp.fraction = 0
            m.itemPoster.translation = [0, 0]
            'm.starRatingRect.opacity = 0
        end if
        'm.descLabel.height      = m.top.currRect.height - m.itemPoster.height - 29
        'm.descLabel.translation = [4, m.top.currRect.height-m.descLabel.height+15]
    end function
]]>
</script>

<children>
    <!--
    <Rectangle id="theRect" color="0xff050540">
        <Label id="theLabel" translation="[6, 3]" font="font:SmallBoldSystemFont" />
        <Label id="descLabel" translation="[6, 150]" lineSpacing="0"  font="font:SmallestSystemFont" wrap="true" />
    </Rectangle>
    -->
    <Poster id="itemPoster" loadDisplayMode="scaleToFit" failedBitmapUri="pkg:/images/no-poster.jpg" loadingBitmapUri="pkg:/images/loading-poster.png"/>
    <!--  
    <Rectangle id="starRatingRect" color="0x000000a0" width="50" height="30" >
        <Label id="starRatingLabel" font="font:SmallestSystemFont" width="50" height="30" horizAlign="center" vertAlign="center" lineSpacing="0" /> 
    </Rectangle>
    -->
    <ColorFieldInterpolator id="focusColorInterp" key="[0.0, 1.0]" keyValue="[0x2C5A7B40, 0x2C5A7Beb]" />
</children>

</component>
