var swfParams = {
    quality: "high",
    allowScriptAccess: "always",
    bgcolor: "#000000",
    allowfullscreen: "true",
    allowNetworking: "all",
    wmode: "transparent"
};

function extend(destination, source) {
    for (property in source) {
        destination[property] = source[property];
    }
    return destination;
}

function renderVideo(url, width, height, vars, params, mid) {
    var isMid = (function () { return /(iPhone|iPad|iPod|Android)/ig.test(navigator.userAgent); })();
    if (!isMid) {
        swfobject.embedSWF(url, 'player', width, height, '9.0.0', null, vars, extend(swfParams, params));
    } else if (mid == true) {
        var win = window.parent;
        var $ = win.jQuery;
        win.dm456.player.setWide(true);
        $.get('/aspx/GetUrl.ashx', { vid: win.dm456.pv, vt: win.dm456.ps }, function (msg) {
            var data = eval(msg);
            if (data.success == 0) {
                document.getElementById('player').innerHTML = '<div class="tip">非常抱歉，本播放地址暂不支持您的设备:(，请使用其它播放地址。 </div>';
            }
            else {
                var _url = data.url;
                if (win.dm456.ps == 'qiyi') {
                    LoadJs.Load(_url, function () {
                        _url = ipadUrl.data.url;
                        player(_url, width, height);
                    });
                }
                else {
                    player(_url, width, height);
                }
            }
        });
    } else {
        document.getElementById('player').innerHTML = '<div class="tip">非常抱歉，本播放地址暂不支持您的设备:( </div>';
    }
}

function player(url, width, height) {
    var s = [];
    s.push('<video id="video" width="' + width + '" height="' + height + '" controls="controls" autoplay="autoplay" x-webkit-airplay="allow">');
    s.push("<source src=" + url + ' type="video/mp4" />');
    s.push("</video>");
    document.getElementById('player').innerHTML = s.join('');
}

var LoadJs = {
    ie: /msie/.test(window.navigator.userAgent.toLowerCase()),
    moz: /gecko/.test(window.navigator.userAgent.toLowerCase()),
    Loaded: function (obj, fCallback) {
        if (this.ie) {
            obj.onreadystatechange = function () {
                if (this.readyState == 'loaded' || this.readyState == 'complete') {
                    fCallback()
                }
            }
        } else if (this.moz) {
            obj.onload = function () {
                fCallback()
            }
        } else {
            fCallback()
        }
    },
    Load: function (sUrl, fCallback) {
        var _script = document.createElement('script');
        _script.setAttribute('type', 'text/javascript');
        _script.setAttribute('charset', 'utf-8');
        _script.setAttribute('src', sUrl);
        document.getElementsByTagName('head')[0].appendChild(_script);
        this.Loaded(_script, fCallback)
    }
};