﻿// jscript library for the client. no page specific code

var Cli_ItemStatusDownloading = 6;
var Cli_ItemStatusPaused = 9;
var Cli_ItemStatusDownloaded = 10;
var Cli_ItemStatusBuyToOwn = 13;


//-------------------------------------------------------------------------------
function CliItemIsPaused( item )
{
    ///<summary>Determine if the item is currently a paused download</summary>

    var state = item.State;
    
    if( state == Cli_ItemStatusPaused )
        return true;
        
    return false;
}

//-------------------------------------------------------------------------------
function CliItemIsDownloading( item )
{
    ///<summary>Determine if the item is currently downloading</summary>

    var state = item.State;
    
    if( state == Cli_ItemStatusDownloading )
        return true;
    if( state == 3 )//backoff
        return true;
    if( state == 4 )//connecting
        return true;
        
    return false;
}

//-------------------------------------------------------------------------------
// check if a library tiem is a bookmark
//
function CliIsItemABookmark( item ) // : bool
{
    var state = item.State;

    if( state == 5 )
        return true;
        
    return false;
}

//-------------------------------------------------------------------------------
// check if a library item is downloaded
//
function CliIsItemDownloaded( item ) // : bool
{
    var state = item.State;

    if( state == 10 )
        return true;
        
    return false;
}


//-------------------------------------------------------------------------------
// check a library item and determine if it is a download item
//
function CliIsItemADownload( item ) // : bool
{
    var state = item.State;
    
    if( state == 6 )//dl - Cli_ItemStatusDownloading
        return true;
    if( state == 9 )//pause
        return true;
    if( state == 10 )//ready - Cli_ItemStatusDownloaded
        return true;
    if( state == 11 )//partview
        return true;
    if( state == 12 )//view
        return true;
    if( state == 13 )//buytoown
        return true;
    if( state == 2 )//queued
        return true;
    if( state == 3 )//backoff
        return true;
    if( state == 4 )//connecting
        return true;
        
    return false;
}


//--------------------------------------------------------------------------------
function CliPause( propositionInstance, mediaContentId )
{
    ///<summary>Pause a download</summary>
    ///<param name="propositionInstance">A pre-authorised instance of ComPropositionInstance</param>
    ///<param name="mediaContentId">The kontiki id of the item to bookmark</param>
    
    propositionInstance.VideoLibraryActions.Pause( mediaContentId );                       
}

//--------------------------------------------------------------------------------
function CliResume( propositionInstance, mediaContentId )
{
    ///<summary>Resume a paused download</summary>
    ///<param name="propositionInstance">A pre-authorised instance of ComPropositionInstance</param>
    ///<param name="mediaContentId">The kontiki id of the item to bookmark</param>

    propositionInstance.VideoLibraryActions.Resume( mediaContentId );                       
}

//--------------------------------------------------------------------------------
function CliRemove( propositionInstance, mediaContentId )
{
    ///<summary>Removes an item fomr the library</summary>
    ///<param name="propositionInstance">A pre-authorised instance of ComPropositionInstance</param>
    ///<param name="mediaContentId">The kontiki id of the item to delete or unbookmark</param>

    propositionInstance.VideoLibraryActions.Remove( mediaContentId );    
    
    //Also remove the item from the cache if it's there
    var cache = new CliLibraryCache(propositionInstance);
    cache.RemoveItem(mediaContentId);                   

}
