﻿/* Common js for m123 */

/* Handles all flash (animations, movies) inside articles. Requires SWObject. */
var NPFlash_article = (function () {
    //*** Private
    //Default data for animations
    var _AnimationDefaults = { Width: 550, Height: 265, domId: "Flash" };
    //Default data for video
    var _VideoDefaults = { Width: 782, Height: 440, WidthSmall: 215, HeightSmall: 265 };
    // flowplayer
    var _FlowplayerURL = strApplicationRoot + "include/flowplayer/flowplayer-3.2.2.swf";

    function _showAnimation(Data) {
        var Flash;
        if (document.getElementById(_AnimationDefaults.domId)) {
            document.getElementById("Flash").style.display = "block";

            Flash = new SWFObject(Data.URL, "flashArticle", Data.Width, Data.Height, "8.0", "#E0DCD1");
            Flash.addParam("wmode", "opaque");
            Flash.write("Flash");
        }
    }

    function _showVideo(Data) {
        _videoSmallPlayer();
    }

    function _videoSmallPlayer() {
        /* The small player is used as a "button" to launch the larger version.*/
        flowplayer("flowplayer_1", { src: _FlowplayerURL, wmode: "opaque" }, {
            clip: {
                autoBuffering: true,
                autoPlay: false,
                onResume: function () {
                    _videoLargePlayer();
                }
            },
            plugins: {
                controls: null
            }
        });
    }

    /* Clears out the small player, reshapes the container and starts a new player */
    function _videoLargePlayer() {
        //hide flash animation if present
        $("#" + _AnimationDefaults.domId).css("visibility", "hidden");
        //show close button
        $("#flowplayer_1").siblings(".btnClose").show().bind("click", function () { _videoReset() });
        //fire up large player
        $("#flowplayer_1").removeClass("flowsmall").addClass("flowlarge").empty().animate({ left: "-567px", height: "440px", width: "782px" }, "slow", "swing", function () {
            flowplayer("flowplayer_1", { src: _FlowplayerURL, wmode: "opaque" }, { clip: { autoPlay: true} });
        });
    }

    /* Hides large players, reinstates small player */
    function _videoReset() {
        //hide close button
        $("#flowplayer_1").siblings(".btnClose").hide().unbind();
        //fire up small player
        $("#flowplayer_1").removeClass("flowlarge").addClass("flowsmall").empty().animate({ left: "0px", height: _VideoDefaults.HeightSmall + "px", width: _VideoDefaults.WidthSmall + "px" }, "slow", "swing", function () {
            _videoSmallPlayer();
            $("#" + _AnimationDefaults.domId).css("visibility", "visible");
        });
    }

    //*** Public
    return {
        showVideo: function (Data) {
            if (!(Data)) {
                Data = {};
            }
            //set default width
            if (!(Data.Width)) {
                Data.Width = _VideoDefaults.Width;
            }
            //set default height
            if (!(Data.Height)) {
                Data.Height = _VideoDefaults.Height;
            }
            _showVideo(Data);
        },
        showAnimation: function (Data) {
            //set default width
            if (!(Data.Width)) {
                Data.Width = _AnimationDefaults.Width;
            }
            //set default height
            if (!(Data.Height)) {
                Data.Height = _AnimationDefaults.Height;
            }
            _showAnimation(Data);
        }
    }

})();
