<script xmlns="http://www.nokia.com/ns/cep/script/1.0/"
xmlns:cep="http://www.nokia.com/ns/cep/1.0/">
    <!-- Pause breathing/blinking if phone is facing down -->
    <if>
        <and>
            <!-- New orientation event with value 'DisplayDownwards' -->
            <contextUpdated>
                <contextRef source='Sensor' type='Event.Orientation'/>
    	      </contextUpdated>
    	      <equals>
                <contextRef source='Sensor' type='Event.Orientation'/>
                <string>DisplayDownwards</string>
    	      </equals>
        </and>
        <actions>
            <!-- Pause breathing/blinking -->
            <light target='Navikey' cmdType='PAUSE'/>
        </actions>
    </if>
    <!-- Resume breathing/blinking if phone is facing up -->
    <elseIf>
        <and>
            <!-- New orientation event with value 'DisplayUpwards' -->
            <contextUpdated>
                <contextRef source='Sensor' type='Event.Orientation'/>
    	      </contextUpdated>
    	      <equals>
                <contextRef source='Sensor' type='Event.Orientation'/>
                <string>DisplayUpwards</string>
    	      </equals>
        </and>
        <actions>
            <!-- Resume breathing/blinking -->
            <light target='Navikey' cmdType='RESUME'/>
        </actions>
    </elseIf>
    <!-- If browser is runnng on foreground and inactivity detected, go to dim mode. -->
    <!-- But if keylocked or device locked, don't go to dim mode. -->
    <elseIf>
        <and>
            <contextUpdated>
                <contextRef source='SysAp' type='LightEvent.InactivityDetected'/>
            </contextUpdated>
            <equal>
                <contextRef source='Application.State' type='Foreground.Application' evaluationDelay='0'/>
                <string>BrowserNG</string>
            </equal>
        </and>
        <actions>
            <light target='PrimaryDisplay' cmdType='DIMMING_ON'/>
        </actions>
    </elseIf>
    <!-- If browser stops running, out of dim mode. -->
    <elseIf>
        <and>
            <notEqual>
                <contextRef source='Application.State' type='Foreground.Application' evaluationDelay='0'/>
                <string>BrowserNG</string>
            </notEqual>
            <notEqual>
                <contextRef source='Application.State' type='Background.Application' evaluationDelay='0'/>
                <string>BrowserNG</string>
            </notEqual>
        </and>
        <actions>
            <light target='PrimaryDisplay' cmdType='DIMMING_OFF'/>
        </actions>
    </elseIf>
    <!-- If browser is going back xto background, out of dim mode. -->
    <elseIf>
        <equal>
            <contextRef source='Application.State' type='Background.Application' evaluationDelay='0'/>
            <string>BrowserNG</string>
        </equal>
        <actions>
            <light target='PrimaryDisplay' cmdType='DIMMING_OFF'/>
        </actions>
    </elseIf>
    <!-- If browser is runnng either on foreground or background and activity detected, out of dim mode. -->
    <elseIf>
        <and>
            <contextUpdated>
                <contextRef source='SysAp' type='LightEvent.ActivityDetected'/>
            </contextUpdated>
            <or>
                <equal>
                    <contextRef source='Application.State' type='Foreground.Application' evaluationDelay='0'/>
                    <string>BrowserNG</string>
                </equal>
                <equal>
                    <contextRef source='Application.State' type='Background.Application' evaluationDelay='0'/>
                    <string>BrowserNG</string>
                </equal>
            </or>
        </and>
        <actions>
            <light target='PrimaryDisplay' cmdType='DIMMING_OFF'/>
        </actions>
    </elseIf>
</script>