﻿
var controlInterfaceWidth = 400;
var VideoContainerId = "VideoContainer";
var FlashScruberId = "FlashScruber";
var wmvPlayerId = "wmvPlayer";
var nextvideolink = "";


if (!window.Tfo) window.Tfo = { Web: { UI: {}} };
if (!Tfo.Web) Tfo.Web = { UI: {} };
if (!Tfo.Web.UI) Tfo.Web.UI = {};

Tfo.Web.UI.MediaPlayer =
{
    IsSilverlightInstalled: function() {
        return (window.Silverlight && Silverlight.isInstalled(null));
    },

    CreateSilverlightPlayer: function(targetElement, playerSource, fileUrl, imageUrl, width, height, showNavigation, backColor, frontColor, lightColor, autoStart, nextVideoLink) {
        if (showNavigation)
            height += 20;

        if (typeof (targetElement) == 'string')
            targetElement = document.getElementById(targetElement);

        var cfg = {
            height: height,
            width: width,
            file: fileUrl,
            image: imageUrl,
            shownavigation: showNavigation ? 'true' : 'false',
            backcolor: backColor,
            frontcolor: frontColor,
            lightcolor: lightColor,
            autostart: autoStart ? 'true' : 'false',
            nextvideolink: nextVideoLink
        };

        var player = new jeroenwijering.Player(targetElement, playerSource, cfg);
    },

    WriteWindowsMediaPlayer: function(targetElementID, fileUrl, width, height, showNavigation, autoStart) {
        if (typeof (targetElementID) == 'string')
            targetElementID = document.getElementById(targetElementID);
        if (showNavigation)
            height += 64;

        var objectID = targetElementID.id + "_Object";
        var markup =
          '<object id="' + objectID + '" classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" height="' + height + '" width="' + width + '">' +
          '  <param name="uiMode" value="' + (showNavigation ? 'full' : 'none') + '">' +
          '  <param name="autoStart" value="' + autoStart + '">' +
          '  <param name="volume" value="90">' +
          '  <param name="AllowChangeDisplaySize" value="true">' +
          '  <param name="enableContextMenu" value="true">' +
          '  <param name="stretchToFit" value="true">' +
          '  <param name="URL" value="' + fileUrl + '">' +
          '</object>' +
          '<embed TYPE="video/x-ms-wmv"' +
          '   uimode="' + (showNavigation ? 'full' : 'none') + '"' +
          '		pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"' +
          '		src="' + fileUrl + '"' +
          '		Name="' + objectID + '"' +
          '		AnimationAtStart="0"' +
          '   AutoStart="' + (autoStart ? 'true' : 'false') + '"' +
          '		Width="' + width + '"' +
          '   Height="' + height + '"' +
          '		transparentAtStart="1"' +
          '		ShowStatusBar="' + (showNavigation ? 'true' : 'false') + '"' +
          '		ShowControls="' + (showNavigation ? 'true' : 'false') + '"' +
          '		autoSize="1"' +
          '		displaySize="1">' +
          '</embed>';

        //    markup =
        //      '<object' +
        //      '   type="video/x-ms-wmv"' +
        //      '   data="' + fileUrl + '"' +
        //      '   width="' + width + '"' +
        //      '   height="' + height + '">' +
        //      '  <param name="src" value="' + fileUrl + '" />' +
        //      '  <param name="autostart" value="' + (autoStart ? 'true' : 'false') + '" />' +
        //      '  <param name="controller" value="' + (showNavigation ? 'true' : 'false') + '" />' +
        //      '</object>';

        targetElementID.innerHTML = markup;
    },

    CreateFlashPlayer: function(videoElement, controlElement, scrubberSource, fileUrl, imageUrl, width, height, showNavigation, autoStart, nextVideoLink) {
        if (typeof (videoElement) == 'string')
            videoElement = document.getElementById(videoElement);
        if (typeof (controlElement) == 'string')
            controlElement = document.getElementById(controlElement);

        controlInterfaceWidth = width;
        VideoContainerId = videoElement.id;
        FlashScruberId = controlElement.id + '_Scrubber';
        wmvPlayerId = videoElement + '_Player';
        nextvideolink = nextVideoLink;

        if (showNavigation) {
            var so = new SWFObject(scrubberSource, FlashScruberId, width, "20", "9");
            so.write(controlElement.id);
        }

        setupWindowsMedia(fileUrl, 1, width, height);

        if (showNavigation) {
            var player = document.getElementById(wmvPlayerId);

            player.attachEvent('playStateChange', wmpPlayStateChange);
            player.attachEvent('mediaChange', wmpMediaChange);
        }
    }
};
