function ClsRealPlayer(cfg) {
	var _this = this;
	_this.for_public = false;
	_this.video_id = '__real_player';
	_this.renderto = null;
	_this.use_window = true;
	_this.ctnr_panel = null;
	_this.ctnrpanel_baseCls = false;
	_this.panel_border_cssstyle = false;
	this.show_playerswitch = true;
	this.show_speedswitch = false;
	this.speed_click_handler = function(e,tool_el,panel){return 1;}	//此函数必须返回speed, 用以维护本播放类的speed属性
	this.speed = 1;
	_this.bl_w = 352;	//比例宽
	_this.bl_h = 288;	//比例高
	_this.w = 422;
	_this.h = 345;
	this.maxmized = false;
	_this.w1 = 352;
	_this.h1 = 288;
	_this.w2 = 422;
	_this.h2 = 345;
	
	_this.panel_toolbar_height = 25;
	_this.videobar_height = 26;
	_this.hofw = _this.videobar_height+30;
	_this.wofw = 12;
	_this.hofp = _this.videobar_height+_this.panel_toolbar_height;
	_this.wofp = 0;
	
	_this.window = null;
	_this.winpel = null;
	_this.panel = null;
	
	this.hdl_switchplayer = function(id,title,w,h,maxmize){}
	this.hdl_savevideosize = function(w,h,maxmize){}

	var m_title = '';
	var m_id = 0;
	
	var m_tools_refresh_sh = false;
	
	var getWinW = function(vw) {
		return vw + _this.wofw;
	}
	var getWinH = function(vh) {
		return vh + _this.hofw;
	}
	var getPnlW = function(vw) {
		return vw + _this.wofp;
	}
	var getPnlH = function(vh) {
		return vh + _this.hofp;
	}
	var getVnlH = function(vh) {
		return vh + _this.videobar_height
	}
	var getVdoW = function(ww) {
		return ww - _this.wofw
	}
	var getVdoH = function(wh) {
		return wh - _this.hofw
	}
	var getVdoWByPanel = function(ww) {
		return ww - _this.wofp
	}
	var getVdoHByPanel = function(wh) {
		return wh - _this.hofp
	}
	
	var resizePanel = function(w,h) {
		_this.ctnr_panel.setSize(w,h);	
	}
	var resizeByPnlSize = function(w,h) {
		var v_w = getVdoWByPanel(w);
		var v_h = getVdoHByPanel(h);
		var vdo_w = 352;
		var vdo_h = 288;
		
		//计算视频大小
		//假设高合适
       	vdo_h = v_h;
        vdo_w = Math.ceil(_this.bl_w * vdo_h / _this.bl_h);
        if (vdo_w > v_w) {	//高不合适
        	//宽合适
        	vdo_w = v_w;
        	vdo_h = Math.ceil(_this.bl_h * vdo_w / _this.bl_w);
        }
        
        _this.w = vdo_w;
        _this.h = vdo_h;
        
        client_wh = _this.winpel.getSize();
        
        //计算容器panel左上角位置
        var client_w = client_wh.width;
        var client_h = client_wh.height;
        var x = Math.ceil((client_w - getPnlW(vdo_w)) / 2);
        var y = Math.ceil((client_h - getPnlH(vdo_h)) / 2);
		//alert(client_w + ":" + vdo_w + "\r\n\r\n" + client_h + ":" + vdo_h + "\r\n\r\n" + "x:" + x + ",y:" + y);
        
        if (_this.ctnr_panel) {
        	_this.ctnr_panel.setPosition(x,y);
        	_this.ctnr_panel.setSize(w,h);
        }

	    if (_this.panel) {
	    	_this.panel.setPosition(0,0);
	    	_this.panel.setSize(vdo_w, getVnlH(vdo_h));
	    }
        //
        var player = _this.getPlayer();
        if (player) {
	        player.width = vdo_w;
	        player.height = vdo_h;
	        //
	        $(_this.video_id+'_sb').width = vdo_w-44;
        }
        
        if (_this.panel) _this.panel.doLayout();
        try{_this.ctnr_panel.doLayout();}catch(e){}	//使用try是因为初始化时，panel还没有加载完成完全可用，不然会有错误
	}
	
	var resizeWindow = function(w,h) {
		_this.window.setSize(w,h);
	}
	var resizeByWinSize = function(w,h) {
		var v_w = getVdoW(w);
		var v_h = getVdoH(h);
		var vdo_w = 352;
		var vdo_h = 288;
		
		//计算视频大小
		//假设高合适
       	vdo_h = v_h;
        vdo_w = Math.ceil(_this.bl_w * vdo_h / _this.bl_h);
        if (vdo_w > v_w) {	//高不合适
        	//宽合适
        	vdo_w = v_w;
        	vdo_h = Math.ceil(_this.bl_h * vdo_w / _this.bl_w);
        }
        
        _this.w = vdo_w;
        _this.h = vdo_h;

        //计算视频panel左上角位置
        var client_w = w-_this.wofw;
        var client_h = h-_this.hofw;
        var x = Math.ceil((client_w - vdo_w) / 2);
        var y = Math.ceil((client_h - vdo_h) / 2);
        //alert(client_w + ":" + vdo_w + "\r\n\r\n" + client_h + ":" + vdo_h + "\r\n\r\n" + "x:" + x + ",y:" + y);
        
        if (_this.ctnr_panel) {
        	_this.ctnr_panel.setPosition(0,0);
        	_this.ctnr_panel.setSize(w,h);
        }
        
        if (_this.panel) {
	        _this.panel.setPosition(x,y);
	        _this.panel.setSize(vdo_w, getVnlH(vdo_h));
        }
        //
        var player = _this.getPlayer();
        if (player) {
	        player.width = vdo_w;
	        player.height = vdo_h;
	        //
	        $(_this.video_id+'_sb').width = vdo_w-44;
        }
                
        _this.panel.doLayout();
        _this.window.doLayout();
	}
	
	var createPPanel = function() {
		if (_this.ctnr_panel==null) {
			if (_this.renderto) {
				var tools = [
					{id:'minus',qtip:'缩小',handler:function(e,tool_el,panel){
						resizePanel(getPnlW(_this.w1), getPnlH(_this.h1));
						//resizeByWinSize(getWinW(_this.w1), getWinH(_this.h1));
					}},
					{id:'plus',qtip:'放大',handler:function(e,tool_el,panel){
						resizePanel(getPnlW(_this.w2), getPnlH(_this.h2));
						//resizeByWinSize(getWinW(_this.w2), getWinH(_this.h2));
					}}
				];
				if (_this.show_playerswitch) {
					tools.unshift({id:'refresh',qtip:'用QuickTime播放',handler:function(e,tool_el,panel){
						_this.hdl_switchplayer(m_id, m_title, _this.w, _this.h, _this.maxmized);
						//resizeByWinSize(getWinW(_this.w1), getWinH(_this.h1));
					}});
				}
				if (_this.show_speedswitch) {
					tools.unshift({id:'speed',qtip:'切换播放速度',handler:function(e,tool_el,panel){
						_this.speed = _this.speed_click_handler(e,tool_el,panel);
					}});
				}
				//tools.push({id:'maximize',qtip:'最大化',handler:function(e,tool_el,panel){
				//	//_this.hdl_switchplayer(m_id, m_title, _this.w, _this.h, _this.maxmized);
				//	//resizeByWinSize(getWinW(_this.w1), getWinH(_this.h1));
				//	
				//	_this.ctnr_panel.header.setDisplayed(false);	//隐藏panel的标题栏，从而隐藏panel上的tools，因为window上有tools
				//	
				//	createWindow(false);
				//	_this.window.add(_this.ctnr_panel);
				//	
				//	_this.window.show();
				//	//
				//	_this.maxmized = true;
				//	if (_this.maxmized) {
				//		_this.window.maximize();
				//		var tmpsize = _this.window.getSize();
				//		resizeByWinSize(tmpsize.width, tmpsize.height);
				//	}
				//}});
			}
			var pnl_obj = {
				layout:'absolute', x:0, y:0,
				/*anchor:"100% 100%",*/
				width:getPnlW(_this.w), height:getPnlH(_this.h),
				border:(_this.panel_border_cssstyle ? true : false), bodyStyle:"padding:0px; margin:0px; background:#000000"+(_this.panel_border_cssstyle ? "; border:"+_this.panel_border_cssstyle : ""),
				listeners: {
					'resize' : function(win, width, height) {
						if (!_this.renderto) return false;
						//win.center();
						//调整视频大小
						resizeByPnlSize(width, height);
					}
				}
			}
			if (_this.renderto) {
				pnl_obj.header = true;
				pnl_obj.tools = tools;
			}
			if (_this.ctnrpanel_baseCls) pnl_obj.baseCls = _this.ctnrpanel_baseCls;
			_this.ctnr_panel = new Ext.Panel(pnl_obj);
		}
		return _this.ctnr_panel;
	}
	
	var createWinpnl = function() {
		if (_this.winpel==null) {
			var pnl_obj = {
				layout:'absolute', x:0, y:0,
				/*anchor:"100% 100%",*/
				width:_this.w+_this.wofp, height:_this.h+_this.hofp,
				border:false, bodyStyle:"padding:0px; margin:0px; background:#000000"
			}
			_this.winpel = new Ext.Panel(pnl_obj);
		}
		return _this.winpel;
	}
	var createWindow = function(closable) {
		if (typeof(closable)=='undefined' || closable==null) closable = true;
		if (_this.window==null) {
			var tools = [
				{id:'minus',qtip:'缩小',handler:function(e,tool_el,panel){
					resizeWindow(getWinW(_this.w1), getWinH(_this.h1));
					//resizeByWinSize(getWinW(_this.w1), getWinH(_this.h1));
				}},
				{id:'plus',qtip:'放大',handler:function(e,tool_el,panel){
					resizeWindow(getWinW(_this.w2), getWinH(_this.h2));
					//resizeByWinSize(getWinW(_this.w2), getWinH(_this.h2));
				}}
			];
			if (_this.show_playerswitch) {
				tools.unshift({id:'refresh',qtip:'用RealPlayer播放',handler:function(e,tool_el,panel){
					_this.hdl_switchplayer(m_id, m_title, _this.w, _this.h, _this.maxmized);
					//resizeByWinSize(getWinW(_this.w1), getWinH(_this.h1));
				}});
			}
			_this.window = new Ext.Window({
				closeAction: 'close', modal: false, plain: true, resizable: false, header: true,
				title: '',
				closable: closable, shadow: true,
				maximizable: true,
				width: getWinW(_this.w), autoHeight: false,
				height: getWinH(_this.h),
				bodyStyle: 'padding:0px;',
				border: false,
				defaults: {border:false},
				listeners: {
					'close' : function(){
						_this.close();
					},
					'resize' : function(win, width, height) {
						win.center();
						//调整视频大小
						resizeByWinSize(width, height);
					},
					'maximize' : function(win) {
						_this.maxmized = true;
						
						_this.window.tools.minus.hide();
						_this.window.tools.plus.hide();
						if (_this.show_playerswitch) {
							m_tools_refresh_sh = _this.window.tools.refresh.isVisible();
							try{_this.window.tools.refresh.hide();}catch(e){}
						}
					},
					'restore' : function(win) {
						_this.maxmized = false;
						if (!_this.renderto) {
							forceRestoreWinsize();
							
							_this.window.tools.minus.show();
							_this.window.tools.plus.show();
							if (_this.show_playerswitch) {
								try{
									if (m_tools_refresh_sh) _this.window.tools.refresh.show();
								}catch(e){}	//当解决了real控件放大缩小后却不变的问题时，这个可以去掉
							}
						}
						else{
							if (_this.w > _this.w2) {
								_this.w = _this.w1;
								_this.h = _this.h1;
							}
							_this.winpel.add(_this.ctnr_panel);
							_this.winpel.doLayout();
							_this.window.hide();
						}
					}
				},
				tools:tools
			});
		}
		return _this.window;
	}
	this.createPlayer = function() {
		if (_this.panel==null) {
			var player_str = getPlayerString(_this.w, _this.h);

			_this.panel = new Ext.Panel({
				header: false, width:_this.w, height:getVnlH(_this.h), defaults: {border:false}, border:false
				/*,layout:'fit', anchor:'100%'*/
				,layout:'absolute', x:0, y:0
				,bodyStyle: 'background:#000000'
				/*,items:[
					{xtype:'panel', id:_this.panel_id, layout:'fit'}
				]*/
				,html: player_str
			});
		}
		return _this.panel;
	}
	this.play = function(camera_id, title, url) {
		m_title = title;
		m_id = camera_id;
		var is_first = (_this.panel==null ? true : false);
		
		_this.createPlayer();
		
		//显示播放器
		createPPanel();
		_this.ctnr_panel.add(_this.panel);
		//
		if (!_this.renderto) {
			createWindow();
			_this.window.add(_this.ctnr_panel);
			_this.window.show();
			//
			if (_this.maxmized) {
				_this.window.maximize();
				var tmpsize = _this.window.getSize();
				resizeByWinSize(tmpsize.width, tmpsize.height);
			}
			
		}
		else{
			createWinpnl();
			_this.winpel.render(_this.renderto);
			
			//得到容器区域的大小
			client_wh = Ext.get(_this.renderto).getSize();
			_this.winpel.setSize(client_wh.width, client_wh.height);	//充满容器区域
			
			_this.winpel.add(_this.ctnr_panel);
			_this.winpel.doLayout();
			
			if (is_first) {
				var tmp_size = _this.ctnr_panel.getSize();
				resizeByPnlSize(tmp_size.width, tmp_size.height);
			}
		}
		_this.showmsg('准备... ' + title);
		
		if (typeof(url)=='undefined' || url==null) {
			if (camera_id>0) {
				_this.showmsg('获取视频... ' + title);
				Ext.Ajax.abort();
				Ext.Ajax.request({
			        url: g_root + 'play_servernew.php',
			        params: {'ids':camera_id, 'public':(_this.for_public ? 1 : 0)},
			        success: function(response, options){
			            try{
				        	var rjdata = Ext.util.JSON.decode(response.responseText);
				        	if (rjdata.urls==false || rjdata.urls=='') {
				        		_this.showmsg(qpDHanzi(rjdata.message) + ' ' + title);
				        	}
				        	else{
				        		_play(rjdata.urls);
				        	}
						}
						catch(e){
							_this.showmsg('意外错误1 ' + title);
							alert(e.message + "\r\n\r\n" + response.responseText);
						}
			        },
			        failure: function(response, options){
			        	if (response.responseText.length>0) {
			        		alert(qpDHanzi(response.responseText), '', '意外错误2');
			        	}
			        	else{
			        		//_this.showmsg('Canceled or No Response ' + title);
			        		_this.showmsg('... ' + title);
			        	}
			        }
			    });
			}
			else{
				_this.showmsg('等待视频... ' + title);
			}
		}
		else{
			_play(url);
		}
	}
	var _play = function(url) {
		if (!url) {
			_this.showmsg('视频地址为空');
			return false;
		}
		url = replaceAll(url, "&amp;", "&");
		var player = _this.getPlayer();
		
		if (!player) {
			_this.showmsg('没有获得播放器');
			return false;
		}
		
		try{
			try{player.DoStop();}catch(e){}
			player.SetSource(url);
			player.DoPlay();
		}
		catch(e){}
		
		_this.showmsg(m_title);
	}
	var forceRestoreWinsize = function() {
		//主要用于窗口被关闭后，再打开窗口时，不按照最大化后的视频尺寸创建窗口，否则点窗口的还原按钮后，只能还原到最大化的视频尺寸
		if (_this.w > _this.w2) {
			_this.w = _this.w1;
			_this.h = _this.h1;
		}
				
		_this.maxmized = false;
		var tmp_w = getWinW(_this.w);
		var tmp_h = getWinH(_this.h);
		_this.window.setSize(tmp_w, tmp_h);
	}
	this.close = function() {
		//因为新开窗口时，播放器的加载时间无法确定，导致最大化窗口后，不能正确设置视频尺寸，所以下面的方法先不用了
		/*//主要用于窗口被关闭后，再打开窗口时，不按照最大化后的视频尺寸创建窗口，否则点窗口的还原按钮后，只能还原到最大化的视频尺寸
		if (_this.w>_this.w2) {
			_this.w = _this.w1;
			_this.h = _this.h1;
		}*/
		//保存视频尺寸
		_this.hdl_savevideosize(_this.w, _this.h, _this.maxmized);
		
		if (_this.ctnr_panel) {_this.ctnr_panel.destroy(); _this.ctnr_panel=null;}
		if (_this.panel) {_this.panel.destroy(); _this.panel=null;}
		if (_this.window) {_this.window.destroy(); _this.window=null;}
	}
	this.showmsg = function(msg) {
		if (!_this.renderto) {
			if (_this.window!=null) _this.window.setTitle(msg);
		}
		else{
			if (_this.ctnr_panel!=null) _this.ctnr_panel.setTitle(msg);
		}
	}
	this.setPlayerSwitcherVisible = function(tf) {
		if (!_this.window) return false;
		if (!_this.window.tools) return false;
		if (!_this.window.tools.refresh) return false;
		
		if (tf) {
			_this.window.tools.refresh.show();
		}
		else{
			_this.window.tools.refresh.hide();
		}
	}
	this.doSwitchplayer = function(id, title) {
		if (typeof(id)=='undefined') id=m_id;
		if (typeof(title)=='undefined') title = m_title;
		this.hdl_switchplayer(id, title, _this.w, _this.h, _this.maxmized);
	}
	this.getVHByW = function(w) {
		//计算画面高
    	vdo_w = w;
    	vdo_h = Math.ceil(_this.bl_h * vdo_w / _this.bl_w);
    	return vdo_h;
	}
	this.getVWByH = function(h) {
		//计算画面宽
		vdo_h = h;
        vdo_w = Math.ceil(_this.bl_w * vdo_h / _this.bl_h);
        return vdo_w;
	}
	this.getPlayer = function() {
		if (Ext.isIE) {
			return $(_this.video_id);
		}
		else{
			return $(_this.video_id+'_FF');
		}
	}
	var getPlayerString = function(w, h) {
		var strx = '<OBJECT ID="'+_this.video_id+'" CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" HEIGHT="'+h+'" WIDTH="'+w+'">';
		strx += '<param name="_ExtentX" value="9313">';
		strx += '<param name="_ExtentY" value="7620">';
		strx += '<param name="AUTOSTART" value="0">';
		strx += '<param name="SHUFFLE" value="0">';
		strx += '<param name="PREFETCH" value="0">';
		strx += '<param name="NOLABELS" value="0">';
		strx += '<param name="SRC" value="">';
		strx += '<param name="CONTROLS" value="ImageWindow">';
		strx += '<param name="CONSOLE" value="Clip1">';
		strx += '<param name="LOOP" value="0">';
		strx += '<param name="NUMLOOP" value="0">';
		strx += '<param name="CENTER" value="0">';
		strx += '<param name="MAINTAINASPECT" value="0">';
		strx += '<param name="BACKGROUNDCOLOR" value="#000000">';
		strx += '<embed name="'+_this.video_id+'_FF" id="'+_this.video_id+'_FF" SRC="" type="audio/x-pn-realaudio-plugin" CONSOLE="Clip1" CONTROLS="ImageWindow" HEIGHT="'+h+'" WIDTH="'+w+'" autostart="false"></embed>';
		strx += '</OBJECT>';
		
		var stra1 = '<OBJECT ID="'+_this.video_id+'_play" CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" WIDTH="44" HEIGHT="26">';
		stra1 += '<PARAM NAME="CONTROLS" VALUE="PlayButton"><PARAM NAME="CONSOLE" VALUE="Clip1">';
		stra1 += '<embed WIDTH=44 HEIGHT=26 CONTROLS="PlayButton" CONSOLE="Clip1" type="audio/x-pn-realaudio-plugin"></embed>';
		stra1 += '</OBJECT>';
		stra1 += '<OBJECT ID="'+_this.video_id+'_sb" CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" WIDTH="'+(w-44)+'" HEIGHT="26">';
		stra1 += '<PARAM NAME="CONTROLS" VALUE="StatusBar"><PARAM NAME="CONSOLE" VALUE="Clip1">';
		stra1 += '<embed WIDTH="'+(w-44)+'" HEIGHT=26 CONTROLS="StatusBar" CONSOLE="Clip1" type="audio/x-pn-realaudio-plugin"></embed>';
		stra1 += '</OBJECT>';
		
		var vdstr = '<table cellpadding="0" cellspacing="0" border="0">';
		vdstr += '<tr><td>' + strx + '</td></tr>';
		vdstr += '<tr><td>' + stra1 + '</td></tr>';
		vdstr += '</table>';
		
		//document.getElementById(_this.video_id).setWantErrors(true);		//出错时不显示对话框
		//document.getElementById(_this.video_id).SetEnableContextMenu(true);
		//alert(document.getElementById("video").GetEnableContextMenu());
		return vdstr;
	}
}