// the title we will attempt to load in later
var title_id = "";

// called by the player when it loads
function onTemplateLoaded() {
    // add event listener, handle the event later in the functions below
    callFlash("addEventListener", "titleLoad", "onTitleLoad");
}

// Handle results of getTitleById call
function getTitleById_Result(infoObj) {
    // If the title isn't already loaded, fetch it
    if (infoObj == undefined) {
        callFlash("fetchTitleById", title_id);

    // otherwise, play it
    } else {
        callFlash("loadTitleById", title_id);
    }
}

function onTitleLoad(infoObj) {
    // extract titleDTO
    var titleDTO = infoObj.parameters.title;

    // play it in the player
    callFlash("loadTitleById", titleDTO.id);
}

// Used to change titles
function swapTitle(videoId) {
    title_id = videoId;
    callFlash("getTitleById", videoId);
    return false;
}

