﻿//Current And Previous Videos for all functions. Empty on page load
//var previousVideoId = "";
//var currentVideoId = "";

//function getThumnailCode(guid) {
//    var str = thumbnails[guid];
//    return str.replace("100", "486");
//}

//function LoadThumbnail(videoId) {
//    var img = getThumnailCode(videoId);
//    if (img == "") {
//        $("#" + videoId + " > .play").remove();
//        $("#" + videoId + " > .load").remove();
//    }
//    $("#" + videoId).css('backgroundImage', 'url("' + img + '")');
//}

//function LoadThumbnails() {
//    $(".video").each(function() {
//        var videoId = $(this).attr("id");
//        LoadThumbnail(videoId);
//    });
//}

//function PlayButtonClickHandler(videoId) {
//    //    var video = $("#" + videoId);
//    var playButton = $("#" + videoId + " > .play");
//    playButton.hide();
//    SetCurrentAndPreviousVideo(videoId);

//    if (previousVideoId != "") {
//        $("#twistage_view_iframe").hide().remove();
//        $("#" + previousVideoId + " > .play").show();
//    }

//    LoadVideo(videoId);
//}

//function SetCurrentAndPreviousVideo(videoId) {
//    previousVideoId = currentVideoId;
//    currentVideoId = videoId;
//}

//Load a video
function LoadVideo(videoId) {
    var videoPlayer = $("#" + videoId + " > .player");
    videoPlayer.html(getIE6EmbedCode(videoId));
    //videoPlayer.html(getEmbedCode(videoId));
}

function RemoveVideo(video) {
    var id = "";
    id = $(video).attr("id");
    $("#" + id + " > .player").empty();
}


function getIE6EmbedCode(guid) {
    var str = embedCode[guid];
    var index = str.indexOf("?v=");
    var id = str.substr(index + 3, 13);
    return getVideoViewer(id, { "width": 486, "height": 274, "player_profile": twistageProfile, "config": { autoplay: true} });
}

function getEmbedCode(guid) {
    var str = embedCode[guid];
    str = str.replace("opaque", "transparent");
    var embed = str.replace("autoplay:false", "autoplay:true");
    return embed;
}

//function ParseEmbedId(embedCode) {
//    var idStart = "";
//    var idEnd = "";
//    idStart = embedCode.indexOf("id=");
//    idEnd = embedCode.indexOf("\"", idStart + 4);
//    var idStr = embedCode.substring(idStart + 4, idEnd);
//    var randomId = idStr + Math.floor(Math.random() * 10001);
//    return embedCode.replace(idStr, randomId);

//}

function LoadInCurrentPage(lastJlogs, title) {
    var jlogList = lastJlogs.split('|');
    RemoveCurrentPage(jlogList);
    jlogList.unshift(document.URL + "^" + title);
    if (jlogList.length > 5) { jlogList.pop(); }
    var jlogText = jlogList.join('|');
    return jlogText;
}

function RemoveCurrentPage(jlogList) {
    for (var i = 0; i < jlogList.length; i++) {
        var oldUrl = jlogList[i].split('^')[0];
        if (oldUrl === document.URL) {
            jlogList.splice(i, 1);
            break;
        }
    }
}