﻿var currentlyPlayingVideo;

function activateVideo(videoId) {
    deactivateVideo();
    currentlyPlayingVideo = videoId;
    $("#videoContainer_" + videoId + " > .open").css({ display: "none" });
    $("#videoContainer_" + videoId + " > .close").css({ display: "inline" });
    $("#videoContainer_" + videoId).animate({
        width: "575",
        height: "300"
    }, 500, function () {
        $("#videoContainer_" + videoId + " > .video").css({ display: "inline" });

        var p = getVideoPlayer(videoId);
        if (typeof (p.startPlayback) == "function") {
            p.startPlayback();
        }
    });

    $("#videoContainer_" + videoId).parent().animate({
        height: 300
    });
}

function deactivateVideo() {
    if (currentlyPlayingVideo == undefined) return;
    videoId = currentlyPlayingVideo;
    currentlyPlayingVideo = undefined;
    var p = getVideoPlayer(videoId);

    if (typeof (p.pausePlayback) == "function") {
        p.pausePlayback();
    }

    $("#videoContainer_" + videoId + " > .video").css({ display: "none" });
    $("#videoContainer_" + videoId).animate({
        width: "185",
        height: "111"
    }, 500, function () {
        $("#videoContainer_" + videoId + " > .open").css({ display: "inline" });
        $("#videoContainer_" + videoId + " > .close").css({ display: "none" });
    });

    $("#videoContainer_" + videoId).parent().animate({
        height: 111
    }, 500);
}

function getVideoPlayer(id) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? document.getElementById(id + "_ie") : document.getElementById(id + "_moz");
}

