﻿
if (!nextEmbedId) {
    var nextEmbedId = 1;
} else {
    nextEmbedId++;
}

var versions = ["0.1"];

if (nextEmbedId == 1) {
    //Only incude these once

    document.write(unescape("%3Cscript src='http://playontv.se/scripts/js/flowplayer/flowplayer.min.js' type='text/javascript'%3E%3C/script%3E"));
}


//jsonp
function PlayOnTV_jsonp(url) {
    var script = document.createElement("script");
    script.setAttribute("src", url);
    script.setAttribute("type", "text/javascript");
    document.body.appendChild(script);
}

function PlayOnTV_getLatestPlayer(containerId, videoId, width, height) {
    PlayOnTV_getPlayer(containerId, videoId, width, height, versions[versions.length - 1]);
}

function PlayOnTV_getPlayer(containerId, videoId, width, height, version) {

    var videoContainer = document.getElementById(containerId);
    PlayOnTV_loadVideo(videoContainer, videoId, width, height, version);
}

function PlayOnTV_loadVideo(videoContainer, videoId, width, height, version) {
    PlayOnTV_jsonp('http://playontv.se/Templates/StockOnTV/Pages/Ajax/EmbedInfo.aspx?video=' + videoId + '&width=' + width + '&height=' + height + '&version=' + version + '&callback=PlayOnTV_loadVideoCallback&containerId=' + videoContainer.id);
}

function PlayOnTV_loadVideoCallback(data) {
    PlayOnTV_includeMarkup(document.getElementById(data.video.containerId), data.video.video, data.video.width, data.video.height, data.video.version, data.video.videoStream, data.video.thumbnail);
    flowplayer("player_" + data.video.video, "http://playontv.se/media/flash/flowplayer/flowplayer.commercial.swf", data.video.playerSettings);
}

function PlayOnTV_includeMarkup(videoContainer, videoId, width, height, version, stream, screenshot) {

    videoContainer.innerHTML = 
        '<div class="player"> \
            <div id="player_' + videoId + '" \
                href="' + stream + '" \
                style="position:relative; display:block;width:' + width + 'px;height:' + height + 'px; background-image:url(' + screenshot + '); background-color:black; background-repeat:no-repeat;"  \
                > \
                <img src="http://playontv.se/media/images/gfx/play_large.png" style="position: absolute; width: 82px; height: 82px; left: 50%; right: 50%; margin-left:-41px;margin-top:' + ((height / 2) - 41) + 'px;" alt="Spela filmen" /> \
                \
                <img src="http://playontv.se/media/images/gfx/Playontv - Logo white.png" style="position: absolute; width: 200px; bottom: 10px; right: 10px;" /> \
            </div> \
        </div>';

}
