var BdPlayer = new Array();

(function(_window , $){

    _window.RGXPlayer =  {

        // 加载
        load   : function(){
            $(this.opts.eleid).css({'width' : '100%' , 'height' : '100%'}).html('<div  style="margin:140px auto 240px auto;width:300px;color:#f0f0f9;font-size:14px;">'
                + '   <p><img src="' + DATA_URL + 'images/loading_black.gif"/> 努力加载中 ... </p></div>');
            return this;
        },

        //  配置信息
        init   : function(opts){
            this.opts = $.extend({
                'eleid'     : '#player_box',
                'ctype'     : '',
                'width'     : '100%',
                'height'    : '100%',
                'url'       : '',
                'ad_load'   : '',
                'ad_pause'  : '',
                'ad_end'    : '',
                'next'      : '',
                'prev'      : '',
            } , opts);
            return this.load();
        },
        // 播放
        play        : function(){
            switch(this.opts.ctype){
                case 'ftp'  :
                case 'bdhd' : 
                    this._bdplay();
                    break;
                case 'qvod' : 
                    this._qvodplay();
                    break;
                case 'swf' : 
                    this._swfplay();
                    break;
            }
        },

        // 百度影音
        _bdplay     : function(){
            BdPlayer['time']         = 8;
            BdPlayer['tn']           = '12345678';
            BdPlayer['url']          = this.opts.url;
            BdPlayer['buffer']       = this.opts.ad_load;
            BdPlayer['pause']        = this.opts.ad_pause;
            BdPlayer['end']          = this.opts.ad_end;
            BdPlayer['width']        = this.opts.width;
            BdPlayer['height']       = this.opts.height;
            BdPlayer['showclient']   = 1;
            BdPlayer['nextcacheurl'] = '';
            BdPlayer['lastwebpage']  = this.opts.prev;
            BdPlayer['nextwebpage']  = this.opts.next;
            BdPlayer['download']     = 'http://dl.client.baidu.com/BaiduPlayer/un/BaiduPlayer_51059058.exe';
            $(this.opts.eleid).html('');
            document.write('<script language="javascript" src="http://php.player.baidu.com/bdplayer/player.js" charset="utf-8"></script>');
        },
        
        // 快播
        _qvodplay       : function(){
            var html  = '<object id="QvodPlayer" name="QvodPlayer" width="' + this.opts.width + '" height="' + this.opts.height;
                html += '" classid="clsid:F3D0D36F-23F8-4682-A195-74C92B03D4AF" onError="window.RGXPlayer._qvodinstall()">';
                html += '<PARAM NAME="URL" VALUE="' + this.opts.url + '">';
                html += '<PARAM NAME="Autoplay" VALUE="1">';
                html += '<PARAM NAME="QvodAdUrl" VALUE="' + this.opts.ad_load + '">';
                html += '<embed URL="' + this.opts.url + '" width="' + this.opts.width;
                html += '" height="' + this.opts.height + '" type="application/qvod-plugin"></embed>';
                html += '</object>';
            $(this.opts.eleid).html(html);
            if(typeof QvodPlayer   == 'undefined'){
                //this._qvodinstall();
            }
        },
        
        // flash播放
        _swfplay        : function(){
            var html  = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
                html += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="100%'
                html += '" height="' + this.opts.height + '">';
                html += '<param name="movie"   value="' + this.opts.url + '" />';
                html += '<param name="quality" value="high" />';
                html += '<param name="wmode"   value="opaque">';
                html += '<param name="allowFullScreen" value="true" />';
                html += '<embed src="' + this.opts.url + '" wmode="opaque" quality="high" allowFullScreen="true"';
                html += 'pluginspage="http://www.macromedia.com/go/getflashplayer"';
                html += 'type="application/x-shockwave-flash" width="100%" height="' + this.opts.height + '"></embed></object>';
            $(this.opts.eleid).css('width' , '100%').html(html);
        },

        // 提示安装
        _qvodinstall        : function(){
            var html  = '<div  style="margin:140px auto 240px auto;width:300px;color:#f0f0f0;font-size:14px;">';
                html += '   <p>您的电脑未安装 Qvodplayer播放软件</p>'
                html += '   <p>';
                html += '       请 <a style="color:#fff" href="http://dl.kuaibo.com/QvodSetupPlus_old.exe" target="_blank">点击下载</a>';
                html += '       安装后刷新本页面播放</p>';
                html += '</div>';
            $(this.opts.eleid).html(html);
        }
    };
})(window , jQuery);