﻿var swfutil = function() {
    this._embedContainer = "FlashContainer";
    this._playerVersion = "8.0.0";
    this._expressInstall = "Scripts/expressInstall.swf";

    return {
        embedSWF: function(source, width, height, options) {
            if (!swfobject) {
                if (window.console) {
                    window.console.log("[FATAL] The swfobject instance is undefined.");
                }
            }
            width           = width   || "100%";
            height          = height  || "100%";
            options         = options || {};
            params          = options.params || { allowScriptAccess: "sameDomain" };
            flashvars       = options.flashVars;
            embedContainer  = options.embedContainer || _embedContainer;
            expressInstall  = options.expressInstall || _expressInstall;
            playerVersion   = options.playerVersion  || _playerVersion;

            if (swfobject.hasFlashPlayerVersion("6.0.65") && 
               (navigator.userAgent.indexOf("Windows NT 6.0") == -1 || swfobject.hasFlashPlayerVersion("9.0.28"))) 
            {
                swfobject.embedSWF(source, embedContainer, width, height, playerVersion, expressInstall, flashvars, params);
                swfobject.expressInstallCallback = function() {
                   swfutil.embedFlashFailImage(source);
                }
            } else {
                swfobject.addDomLoadEvent(function() {
                    swfutil.embedFailImage(source);
                });
            }
        },
        embedFailImage: function(source) {
            var failure  = document.getElementById('FlashFailContainer');
            var noscript = document.getElementById('FlashFailNoScript');
            if (noscript && failure) {
                var src = noscript.innerHTML.match(/src="([^"]+)"/)[1];
                if (src) {
                    failure.innerHTML = "<img src=\"" + src + "\" />";
                }
            }
        }
    };
}();