﻿
var gTVRootID = 0;
var gTVVideoID = 0;
var gTVChannelPath = null;
var gTVSkinPath = "/";

//Display different players depending on type.
function SwitchPlayer(type, projectId, channelPath) {

    //remove player and create containerdiv.
    RecreatePlayerDiv('ki_player');
    
    //switch player.
    if (type == 'synch') {

        //save channelPath
        gTVChannelPath = channelPath;
        gTVVideoID = 0;
    
        //switch player.
        DisplaySynchPlayer(projectId);
        document.getElementById('kstv_backimage').style.display = 'inline';
    }
    else {
        
        DisplayRegularPlayer(gTVChannelPath, gTVRootID, gTVVideoID);
        document.getElementById('kstv_backimage').style.display = 'none';
    }

}

function RecreatePlayerDiv(id) {

    var obj = document.getElementById(id);

    if (obj) {

        var parent = obj.parentNode;
        parent.removeChild(obj);

        var div = document.createElement('div');
        div.id = id;
        parent.appendChild(div);
    }

}

//Displays regular channelplayer.
function DisplayRegularPlayer(channelPath, rootId, videoId) {

    var flashvars = {
        targpathToMovie: channelPath,
        videoId: videoId,
        xmlUrl: "/Pages/ksTV/ksTVCategoryXml.aspx?channel=0",
        target1: rootId,
        xmlUrl2: "/Pages/ksTV/ksTVCategoryXml.aspx?category=1",
        featured1: "/Pages/ksTV/ksTVVideoXml.aspx?featured=2"
    };
    var params = {
        wmode: "transparent",
        quality: "high",
        allowScriptAccess: "always",
        allowFullScreen: "true"
    };
    var attributes = {};

    swfobject.embedSWF("/flash/ki_player.swf", "ki_player", "887", "461", "8", "expressInstall.swf", flashvars, params, attributes);
}

//displays synch player
function DisplaySynchPlayer(projectId) {

    var flashvars = {
        projectId: projectId,
        fileLoadPrefix: gTVSkinPath
    };
    var params = {
        wmode: "transparent",
        quality: "high",
        allowScriptAccess: "always",
        allowFullScreen: true
    };
    var attributes = { };

    swfobject.embedSWF("/flash/karolinska_sync_player.swf", "ki_player", "887", "462", "7", "expressInstall.swf", flashvars, params, attributes);
}
