﻿var currentVideoId = "";

function PlayVideo(videoId, videoResponse, title) {
    if (videoResponse && videoResponse != "") {
        if (currentVideoId != "") {
            var ThumbnailTable_Old = document.getElementById(currentVideoId + "_ThumbnailTable");
            var TitleSpan_Old = document.getElementById(currentVideoId + "_TitleSpan");
            var DescriptionSpan_Old = document.getElementById(currentVideoId + "_DescriptionSpan");

            if (ThumbnailTable_Old) {
                ThumbnailTable_Old.className = ThumbnailTable_Old.className.replace(/\-active/, "");
            }

            if (TitleSpan_Old) {
                TitleSpan_Old.className = TitleSpan_Old.className.replace(/\-active/, "");
            }

            if (DescriptionSpan_Old) {
                DescriptionSpan_Old.className = DescriptionSpan_Old.className.replace(/\-active/, "");
            }
        }

        currentVideoId = videoId;
    
        var ThumbnailTable = document.getElementById(videoId + "_ThumbnailTable");
        var TitleSpan = document.getElementById(videoId + "_TitleSpan");
        var DescriptionSpan = document.getElementById(videoId + "_DescriptionSpan");

        if (ThumbnailTable) {
            ThumbnailTable.className = ThumbnailTable.className.replace(/\-mouseover/, "");
            ThumbnailTable.className += "-active";
        }

        if (TitleSpan) {
            TitleSpan.className = TitleSpan.className.replace(/\-mouseover/, "");
            TitleSpan.className += "-active";
        }

        if (DescriptionSpan) {
            DescriptionSpan.className = DescriptionSpan.className.replace(/\-mouseover/, "");
            DescriptionSpan.className += "-active";
        }        
    
        var commonId = "Default_Header_VideoPlayer";

        //var Default_Header_Video_HeaderText = document.getElementById("Default_Header_Video_HeaderText");
        //Default_Header_Video_HeaderText.innerHTML = title;
    
        var Default_Header_Logo_MainTR = document.getElementById("Default_Header_Logo_MainTR");
        var Default_Header_Login_MainTR = document.getElementById("Default_Header_Login_MainTR");
        var Default_Header_Video_MainTR = document.getElementById("Default_Header_Video_MainTR");

        Default_Header_Logo_MainTR.style.display = "none";
        Default_Header_Login_MainTR.style.display = "none";
        Default_Header_Video_MainTR.style.display = "";

        if (!document.getElementById("Default_Header_VideoPlayer")) {
            VideoPlayer_Build(commonId, videoResponse);
        }
        else {
            var swf = document.getElementById(commonId);
            swf.startIntro(videoResponse);
        }
    }
}

function closeLandingPlayer() {
    if (currentVideoId != "") {
        var ThumbnailTable_Old = document.getElementById(currentVideoId + "_ThumbnailTable");
        var TitleSpan_Old = document.getElementById(currentVideoId + "_TitleSpan");
        var DescriptionSpan_Old = document.getElementById(currentVideoId + "_DescriptionSpan");

        if (ThumbnailTable_Old) {
            ThumbnailTable_Old.className = ThumbnailTable_Old.className.replace(/\-active/, "");
        }

        if (TitleSpan_Old) {
            TitleSpan_Old.className = TitleSpan_Old.className.replace(/\-active/, "");
        }

        if (DescriptionSpan_Old) {
            DescriptionSpan_Old.className = DescriptionSpan_Old.className.replace(/\-active/, "");
        }
    }

    currentVideoId = "";

    var Default_Header_VideoDiv = document.getElementById("Default_Header_VideoDiv");

    while (Default_Header_VideoDiv.hasChildNodes()) {
        Default_Header_VideoDiv.removeChild(Default_Header_VideoDiv.firstChild);
    }

    var Default_Header_Logo_MainTR = document.getElementById("Default_Header_Logo_MainTR");
    var Default_Header_Login_MainTR = document.getElementById("Default_Header_Login_MainTR");
    var Default_Header_Video_MainTR = document.getElementById("Default_Header_Video_MainTR");

    Default_Header_Logo_MainTR.style.display = "";
    Default_Header_Login_MainTR.style.display = "";
    Default_Header_Video_MainTR.style.display = "none";
}

function VideoPlayer_Build(commonId, videoResponse) {
    var vidSwf = new SWFObject(document.getElementById("websiteURL").value + "/flash/LandingPlayer-v6.swf?id=" + Math.random(), commonId, "930", "533", "10");
    vidSwf.addVariable("bwList", document.getElementById("introBwl").value); //"100|-|200|-|400");
    vidSwf.addVariable("ThemeColor", MainColor);
    vidSwf.addVariable("shade", MainShade);
    vidSwf.addVariable("theme", MainTheme);
    vidSwf.addVariable("lang", MainLanguage);
    vidSwf.addVariable("size", "lg");
    vidSwf.addVariable("DefaultVolume", 50);
    vidSwf.addVariable("fps", document.getElementById("vs_p_fps").value); //vs_p_fps
    vidSwf.addVariable("startWidth", 909);
    vidSwf.addVariable("startHeight", 511);
    vidSwf.addVariable("mode", "landing");    
    vidSwf.addVariable("playList", videoResponse);
    vidSwf.addParam("wmode", "transparent");
    vidSwf.addParam("allowFullScreen", "true");
    vidSwf.addParam("allowScriptAccess", "always");
    vidSwf.write("Default_Header_VideoDiv");
    vidSwf = null;
}
