﻿/*===========================================================================
 * 
 *   开发团队：  傲世网:网络研发部
 *   开发人员：  KaiSin
 *   主体开发：  KaiSin
 *   对象功能：  Flash调用无激活框
 *   代码连接：  http://Res.Aoons.Com/JScript/Flash.js
 *   生成日期：  2007/8/16
 *  
 ===========================================================================*/
 //ex:
 //var m = new myFlash('tmp.swf',300,300);
 //m.addParam("参数名","参数值");
 //m.addAttrib("属性名","属性值");
 //m.addVars("变量名","变量值");
 //m.toObject('要输出的对象ID');
var myFlash = function(src, w, h, v)
{
    this.src = src;
    this.w = w;
    this.h = h;
    this.v = (v) ? v : "7,0,19,0";
    this.params = {};
    this.attribs = {};
    this.vars = {};
}

myFlash.NoFlashHTML = '<a href="http://www.macromedia.com/go/getflashplayer/" target="_blank">(请安装新版 Flash Player，否则你将不能浏览该内容)please installed new version flash player;</a>';
myFlash.prototype.addParam = function(n,v){this.params[n] = v;}
myFlash.prototype.addAttrib= function(n,v){this.attribs[n] = v;}
myFlash.prototype.addVars = function(n, v){ this.vars[n] = v; }

myFlash.prototype.getFlash = function()
{
    if (new myFlash.PlayerVersion(this.v).VersionIsValid(myFlash.getPlayerVersion())) { return myFlash.NoFlashHTML; }
    var o = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + this.v + '"';
    var b = '<embed pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"';
    o += ' width="' + this.w + '" height="' + this.h + '"';
    b += ' width="' + this.w + '" height="' + this.h + '" src="' + this.src + '"';

    for (i in this.attribs)
    {
        o += " ";
        o += i;
        o += '="' + this.attribs[i] + '"';

        b += " ";
        b += i;
        b += '="' + this.attribs[i] + '"';
    }

    o += '>';

    for (i in this.params)
    {
        o += '<param name="' + i + '" value="' + this.params[i] + '" />';

        b += " ";
        b += i;
        b += '="' + this.params[i] + '"';
    }
    o += '<param name="movie" value="' + this.src + '" />';

    var vs = "";
    for (i in this.vars)
    {
        vs += '&' + i;
        vs += '=' + this.vars[i];
    }

    if (vs != "")
    {
        vs = vs.substr(1);
        o += '<param name="FlashVars" value="' + vs + '" />';
        b += ' FlashVars="' + vs + '"';
    }

    b += '></embed>';

    o += b;
    o += '</object>';

    return o;
}

//输入到html中
myFlash.prototype.toHtml= function(obj)
{
    if (typeof obj == 'string') 
        obj = document.getElementById(obj);
    if (!obj)
    {
        alert('Not Find myFlash toObject is args obj;');
        return;
    }

    var result = this.getFlash();
    obj.innerHTML = result;
    return result;
}

/*以下两个位附加函数*/
myFlash.prototype.show = function(obj)
{
    if (typeof obj == 'string')
        obj = document.getElementById(obj);
    if (!obj)
    {
        alert('Not Find myFlash toObject is args obj;');
        return;
    }
    obj.style.display = "block"; //
}

myFlash.prototype.hidden = function(obj)
{
    if (typeof obj == 'string')
        obj = document.getElementById(obj);
    if (!obj)
    {
        alert('Not Find myFlash toObject is args obj;');
        return;
    }
    obj.style.display = "none";//
}

myFlash.getPlayerVersion = function()
{
    var _23 = new myFlash.PlayerVersion([0, 0, 0]);
    if (navigator.plugins && navigator.mimeTypes.length)
    {
        var x = navigator.plugins["Shockwave Flash"];
        if (x && x.description)
        {
            _23 = new myFlash.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
        }
    }
    else
    {
        if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0)
        {
            var axo = 1; var _26 = 3; while (axo)
            {
                try
                {
                    _26++;
                    axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + _26);
                    _23 = new myFlash.PlayerVersion([_26, 0, 0]);
                }
                catch (e)
                {
                    axo = null;
                }
            }
        }
        else
        {
            try
            {
                var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
            }
            catch (e)
            {
                try
                {
                    var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
                    _23 = new myFlash.PlayerVersion([6, 0, 21]);
                    axo.AllowScriptAccess = "always";
                }
                catch (e)
                {
                    if (_23.major == 6)
                    {
                        return _23;
                    }
                }
                try
                {
                    axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
                }
                catch (e)
                {
                }
            }
            if (axo != null)
            {
                _23 = new myFlash.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
            }
        }
    }
    return _23;
};

myFlash.PlayerVersion = function(_29)
{
    this.major = _29[0] != null ? parseInt(_29[0]) : 0;
    this.minor = _29[1] != null ? parseInt(_29[1]) : 0;
    this.rev = _29[2] != null ? parseInt(_29[2]) : 0;
    this.VersionIsValid = function(fv)
    {
        if (this.major < fv.major) return false;
        if (this.major > fv.major) return true;
        if (this.minor < fv.minor) return false;
        if (this.minor > fv.minor) return true;
        if (this.rev < fv.rev) return false;
        return true;
    };
};