var IFilePicker = {modeOpen:0, modeSave:1, modeGetFolder:2, modeOpenMultiple:3,returnOK:0, returnCancel:1, returnReplace:2};
var IDOMWindow = {SizeMode_Normal:0, SizeMode_Minimized:1, SizeMode_Maximized : 2};
var IDOMAmbient = {lockpaint:1, locklayout:2, lockcalcregion:4};
var IRegistry = {REG_ERR:-1, REG_NONE:0, REG_SZ:1, REG_EXPAND_SZ:2, REG_DWORD:4, KEY_READ:0x20019, KEY_WRITE:0xF003F, KEY_ALL:0x20019|0xF003F};
var IDOMEvent = {eLeftButton:0, eMiddleButton:1, eRightButton : 2};
var IPlayerState = {pppBuffering:0,pppReady:1,pppPlay:2,pppPause:3,pppStop:4,pppMediaEnd:5};
var IPlayerFileType = {PLAY_NONE:0,PLAY_SYNACAST:1,PLAY_FILE:2,PLAY_VOD:3,PLAY_SHORTVIDEO:4,PLAY_PPVOD:5};
var IResizeCommand = {idResize050:8,idResize100:1,idResize150:2,idResize200:3,idResizeMini:4,idResizeTop:5,idResize16v9:6,idResize4v3:7};
var const_minWidth_list =242;
var const_minWidth_web=484;
var const_minWidth_Player_mini=246;
var const_minHeight_Player_mini=186;
var timerId = 0;
var timerBuffer = 0;
var bufferIndicator = 0;
var curState = IPlayerState.pppStop;
var showMiniPlayer = false;

//var const_minWidth_Player_classic=550
//var const_minHeight_Player_classic=550
//var const_minWidth_Player_modern=550
//var const_minHeight_Player_modern=550

function GetDiskFreeSpace(path)
{
	if(path.length<2) return -1;
	var driver = path.substring(0,1).toUpperCase();
	var colon = path.substring(1,2);
	if(colon!=":" || driver<'A' || driver>'Z') return -1;

	var filepath = Components.GetObject2("@pplive.com/filepath;1");
	if(!filepath) return -1;
	return filepath.GetDiskFreeSpace(driver + ":");
}

function flashDecode(str)
{   
	var s = "";
	if(str.length == 0)   return "";
	s    =    str.replace(/&amp;/g,"&");
	s    =    s.replace(/&lt;/g,"<");
	s    =    s.replace(/&gt;/g,">");
	s    =    s.replace(/&nbsp;/g," ");
	s    =    s.replace(/&apos;/g,"\'");
	s    =    s.replace(/&quot;/g,"\"");
	return   s;   
}
function pppPlayNewItem(next)
{
	var PPP= Components.GetObject2("PPP");
	if(PPP)PPP.PlayNewItem(next);
}

function CanGoNext()
{
	var ppp = Components.GetObject2("PPP");
	if (ppp)
	{
      return ppp.PlayList.CanGoNext();
	}
}

function CanGoPrev()
{
	var ppp = Components.GetObject2("PPP");
	if (ppp)
	{		
      return ppp.PlayList.CanGoPrev();
	}
}
function SetClipRegion() {
    var ad = Components.GetObject2("@pplive.com/ad;1");

    var mframe = Components.GetObject2("mframe");
	if (mframe)
	{
		showMiniPlayer = mframe.MiniPlayerMode;
		
		if (window.$("tabPlayer"))
		{		
		  if (showMiniPlayer||window.$("tabPlayer").selected == false)
		  {
			window.taskbar.SetClipToDefault();
			return;
		  }
		}
	}


    if (ad) {
        if (ad.GetAdState(AD_TYPE.ADT_BUFFERING) != AdEventID.ADE_END) {

            window.taskbar.SetClipToDefault();
            return;
        }
    }

    var ppframe = Components.GetObject("@pplive.com/PPFrame;1");
    if (ppframe) {

        window.taskbar.SetThumbnailClip(ppframe.left, ppframe.top, ppframe.widthPlayer, ppframe.heightPlayer);

    }
}

function BufferingProgressBar() {
    if (bufferIndicator >= 100)
        bufferIndicator = 0;
    var ppp = Components.GetObject2("PPP");
    if (ppp) {
        window.taskbar.SetProgressValue(bufferIndicator, 100);
    }
    bufferIndicator+=3;
}
function OnThumbbarButtonClick(Id)
{

	var ppframe = Components.GetObject("@pplive.com/PPFrame;1");
	if (!ppframe)
	{
		return;
	}
	switch (Id)
	{
	case 100:
		pppPlayNewItem(-1);
		break;
	case 101:
		if (curState == IPlayerState.pppPause || curState == IPlayerState.pppStop)
		{
		 ppframe.Play();
		}
		if (curState == IPlayerState.pppPlay)
		{
			ppframe.Pause();
		}
		break;
	case 102:
		pppPlayNewItem(1);
		break;
	default:
		break;
	}
}

function OnTaskbarButtonCreated()
{


  
	var btn = new Object();
	btn.id = 100;
	btn.tooltip = "前一集";
	btn.icon = ShowAbsolutePath("skins\\common\\previous.ico");
	btn.func = OnThumbbarButtonClick;
	var ButtonArray = new Array();
	ButtonArray[0] = btn;
	btn = new Object();
	btn.id = 101;
	btn.tooltip = "播放";
	btn.icon = ShowAbsolutePath("skins\\common\\play.ico");
	btn.func = OnThumbbarButtonClick;
	ButtonArray[1] = btn;
	btn = new Object();
	btn.id = 102;
	btn.tooltip = "下一集";
	btn.icon = ShowAbsolutePath("skins\\common\\next.ico");
	btn.func = OnThumbbarButtonClick;
	ButtonArray[2] = btn;
	window.taskbar.ThumbBarAddButtons(ButtonArray);
	window.taskbar.UpdateButtonState(100,ShowAbsolutePath("skins\\common\\previous_dis.ico"),true);
	window.taskbar.UpdateButtonState(101,ShowAbsolutePath("skins\\common\\play_dis.ico"),true);
	window.taskbar.UpdateButtonState(102,ShowAbsolutePath("skins\\common\\next_dis.ico"),true);

	var ppframe = Components.GetObject("@pplive.com/PPFrame;1");
	if (ppframe)
	{
		ppframe.mainhwnd = window.hwnd;
	}
	var ppp = Components.GetObject2("PPP");
	if (ppp)
	{		
		EwaOnPlayStateChanged(ppp.State);
	}

    
}
function EwaOnPlayStateChanged(newState) {
    curState = newState;
    var uiMainWindow = Components.GetObject2("@pplive.com/ui/mainwindow;1");
    if (uiMainWindow) {
        if (!EwaIsFullScreen()) {
            var topmost = uiMainWindow.GetTopMostEx();
            if (topmost == 2) {
                if (newState == IPlayerState.pppBuffering || newState == IPlayerState.pppPlay || newState == IPlayerState.pppReady) {
                    uiMainWindow.topmost = true;
                }
                else {
                    uiMainWindow.topmost = false;
                }
            }
        }
        for (var keyname in uiMainWindow.vecOnPlayStateChange) {
            try {
				uiMainWindow.vecOnPlayStateChange[keyname](newState);	
			}
			catch(e)
			{
			}
		}
	}
	var hoverInfo = Components.GetObject2("@pplive.com/hoverinfo;1");
	if(hoverInfo)
	{
		try
		{
			hoverInfo.OnPlayerStateChange(newState);
		}
		catch(e)
		{
		}
	}
	var EWA = Components.GetObject2("EWA");
	if(EWA)
	{
		if(newState==IPlayerState.pppStop || newState==IPlayerState.pppMediaEnd )
		{ 
			if (timerId != 0) 
			{
		                window.clearInterval(timerId);
		                timerId = 0;
		                var ppframe = Components.GetObject("@pplive.com/PPFrame;1");
		                if (ppframe) 
				{
		                    window.taskbar.SetClipToDefault();
							window.taskbar.UpdateButtonState(101, ShowAbsolutePath("skins\\common\\play.ico"), false);
	                }
            }
			$("key_Stop").disabled =true;
			$("menu_Stop").disabled=true;
			$("menu_picMenu").disabled=true;
			try
			{
				$("menu_screenShot").disabled=true;
				$("menu_colorAdjust").disabled=true;
			}
			catch(e)
			{
			}
		}
		else if(newState==IPlayerState.pppBuffering || newState==IPlayerState.pppReady || newState==IPlayerState.pppPlay || newState==IPlayerState.pppPause)
		{
			$("key_Stop").disabled =false;
			$("menu_Stop").disabled=false;
		    $("menu_addinfolder").disabled=false;
			$("menu_picMenu").disabled=false;
			try
			{
				$("menu_definition").disabled=false;
				if(newState==IPlayerState.pppBuffering)
				{
					$("menu_screenShot").disabled=true;
					$("menu_colorAdjust").disabled=true;
				}
				else
				{
					$("menu_screenShot").disabled=false;
					$("menu_colorAdjust").disabled=false;
				}
			}
			catch(e)
			{
			}
		}
	}
	if (!window.taskbar)
	{
		return; 
	}
	  if (timerId == 0 && (newState == IPlayerState.pppPause || newState == IPlayerState.pppPlay)) {

                timerId = window.setInterval(SetClipRegion, 1000);
				if (CanGoNext())
				{
					
					window.taskbar.UpdateButtonState(102,ShowAbsolutePath("skins\\common\\next.ico"),false);
				}
				else
				{
					window.taskbar.UpdateButtonState(102,ShowAbsolutePath("skins\\common\\next_dis.ico"),true);
				}
				if (CanGoPrev())
				{
					window.taskbar.UpdateButtonState(100,ShowAbsolutePath("skins\\common\\previous.ico"),false);
				}
				else
				{
					window.taskbar.UpdateButtonState(100,ShowAbsolutePath("skins\\common\\previous_dis.ico"),true);
				}
               
            }
            if (newState == IPlayerState.pppPause || newState == IPlayerState.pppBuffering) {
                window.taskbar.UpdateButtonState(101, ShowAbsolutePath("skins\\common\\play.ico"), false);
            }
			if (newState == IPlayerState.pppPause)
			{
				window.taskbar.SetOverlayIcon( ShowAbsolutePath("skins\\common\\pp_pause.ico"),"PPTV");
			}
			else
			{
				window.taskbar.SetOverlayIcon(0,"PPTV");
			}
            if (newState == IPlayerState.pppPlay) 
			{			
               window.taskbar.UpdateButtonState(101, ShowAbsolutePath("skins\\common\\pause.ico"), false);			                
            }


            if (newState == IPlayerState.pppBuffering) {

                window.clearInterval(timerBuffer);
                timerBuffer = window.setInterval(BufferingProgressBar, 100);
                
            }
            else {
                
                window.clearInterval(timerBuffer);
                
                timerBuffer = 0;
                bufferIndicator = 0;
            }
}
function $(id)
{
	return document.getElementById(id);
}
function SelectFolder()
{
	var filePicker = Components.CreateObject("@pplive.com/filepicker;1");
	if (filePicker)
	{
		filePicker.init(window, "请选择保存路径", IFilePicker.modeGetFolder);
		var openReturn = filePicker.show();
		if (openReturn != IFilePicker.returnCancel)
		{
			return filePicker.file;
		}
	}
	return "";
}

function OpenFile()
{
	var filePicker = Components.CreateObject("@pplive.com/filepicker;1");
	if (filePicker)
	{
		filePicker.init(window, "打开本地文件", IFilePicker.modeOpen);
		filePicker.appendFilter("媒体文件(所有类型)", "*.asf;*.wm;*.wma;*.wmv;*.avi;*.rm;*.rmvb;*.ra;*.ram;*.rp;*.rpm;*.rt;*.dat;*.m1v;*.m2p;*.mpe;*.mpeg;*.mpg;*.ts;*.mp4;*.m4b;*.m4v;*.mpeg4;*.mov;*.qt;*.3g2;*.3gp;*.3gp2;*.3gpp;*.flv;*.f4v;*.hlv;*.mkv;*.mka;*.aac;*.ape;*.ac3;*.dts;*.wav;*.midi;*.amr;*.mp3");
		filePicker.appendFilter("所有文件(*.*)", "*.*");
		var openReturn = filePicker.show();
		if (openReturn != IFilePicker.returnCancel)
		{
			return filePicker.file;
		}
	}
	return "";
}
function SaveFile()
{
	var filePicker = Components.CreateObject("@pplive.com/filepicker;1");
	if (filePicker)
	{
		filePicker.init(window, "保存", IFilePicker.modeSave);
		//filePicker.appendFilter("文本文件(*.*)", "*.*");
		var saveReturn = filePicker.show();
		if (saveReturn != IFilePicker.returnCancel)
		{
			return filePicker.file;
		}
	}
	return "";
}
function pppPlayString(strPlayString,lwhere)
{
	var uiMainWindow = Components.GetObject2("@pplive.com/ui/mainwindow;1");
	if(uiMainWindow)
	{
		if(uiMainWindow.sizemode == IDOMWindow.SizeMode_Minimized)
		{
			uiMainWindow.sizemode = IDOMWindow.SizeMode_Normal;
		}
	}
	if (strPlayString.length > 0)
	{
		var ppframe = Components.GetObject2("PPFrame");
		try
		{
			ppframe.CreatePlayer();
		}
		catch(e)
		{
		} 
		var PPP= Components.GetObject2("PPP");
		if(PPP)PPP.URL2(strPlayString,lwhere);
	}
}

function EwaVolumeModify(nModifyValue)
{
	var EWA = Components.GetObject2("EWA");
	if(EWA)
	{
		var nVolume=EWA.Volume;
		if(EWA.Mute) nVolume=0;
		if (nVolume<100 && nModifyValue >0)
		{
			nVolume = nVolume + 10;
		}
		else if (nVolume<=100 && nModifyValue <0)
		{
			nVolume = nVolume - 10;
		}
		else if (nVolume>=100 && nModifyValue >0)
		{
			nVolume = nVolume + 20;
		}
		else if (nVolume>100 && nModifyValue <0)
		{
			nVolume = nVolume - 20;
		}
		if(nVolume<0)nVolume=0;
		if(nVolume>1000)nVolume=1000;
		if(nVolume==0)
		{
			EWA.Mute=true;
		}
		else
		{
			EWA.Mute=false;
			EWA.Volume=nVolume;
		}
	}
}

function EwaChangeMute()
{
	var EWA = Components.GetObject2("EWA");
	if(EWA)
	{
		EWA.Mute=!EWA.Mute;
	}
}
function EwaPlayOrPause()
{
	try
	{
		var EWA = Components.GetObject2("EWA");
		if(EWA)
		{
			var state = EWA.PlayState;
			if(state==3 || state==4 || state==5)
			{
				EWA.Play();
			}
			else if(state==2 || state==0)
			{
				EWA.Pause();
			}
		}		
	}
	catch (e)
	{
	}

}
function EwaStop()
{
	var EWA = Components.GetObject2("EWA");
	if(EWA)
	{
		EWA.Stop()
	}
}
function EwaIsFullScreen()
{
	try
	{
		var EWA = Components.GetObject2("EWA");
		if(EWA)
		{
			return EWA.FullScreen;
		}
	}
	catch(e)
	{
		
	}
	return false;
}
function EwaFullScreen()
{
	var EWA = Components.GetObject2("EWA");
	if(EWA)
	{
		EWA.FullScreen=true;
	}
}
function EwaUnFullScreen()
{
	var EWA = Components.GetObject2("EWA");
	if(EWA)
	{
		EWA.FullScreen=false;
	}
}
function EwaFullOrUnfull()
{
	var EWA = Components.GetObject2("EWA");
	if(EWA)
	{
		EWA.FullScreen=!EWA.FullScreen;
	}
}
function realEWAFastForward(advance)
{
	if (window.delayFFTimerId)
	{
		window.clearTimeout(window.delayFFTimerId);
		window.delayFFTimerId = 0;
	}
	var PPP = Components.GetObject2("PPP");
	if(!PPP) return;
	if(PPP.PlayFileType!=2 && PPP.PlayFileType!=5 && PPP.PlayFileType!=6) return;
	var EWA= Components.GetObject2("EWA");
	if(!EWA) return;
	if(EWA.PlayState != 0 && EWA.PlayState != 2 && EWA.PlayState != 3) return;
	
	var pos;
	var tipText;
	if (advance)
	{
		pos= EWA.CurrentPosition + 10;
		if(pos>EWA.Duration && EWA.Duration>0) pos = EWA.Duration;
		tipText = "快进到";
	}
	else
	{
		pos= Math.max(EWA.CurrentPosition - 10 ,0);
		tipText = "快退到";
	}
	EWA.CurrentPosition = pos;

	var mframe = Components.GetObject2("mframe");
	if(mframe && pos)
	{
		if(PPP.PlayFileType==6)
		{
			var dtCurPlay = new Date(pos*1000);
			var h = dtCurPlay.getHours();
			var m = dtCurPlay.getMinutes();
			var s = dtCurPlay.getSeconds();
			if(m<10)m = "0" + m;
			if(s<10)s = "0" + s;
			tipText = tipText + " " + h + ":" + m + ":" + s;
		}
		else
		{
			var m = parseInt(pos / 60);
			var s = parseInt(pos % 60);
			if(s<10)s = "0" + s;
			tipText = tipText + " " + m + ":" + s;
		}
		mframe.TipControl.ShowTipText(tipText,0xcccccc,3);
	}

}

function SetFFUnMute()
{
	if (window.delayFFTimerId)
	{
		return;
	}

	if (window.FFUnMuteId)
	{
		window.clearInterval(window.FFUnMuteId);
		window.FFUnMuteId = 0;
	}

	var ppplayer = Components.GetObject2("PPPlayer");
	if (ppplayer)
	{
		ppplayer.dragging = false;
		if (!ppplayer.bMute)
		{
			var EWA = Components.GetObject2("EWA");
			if (EWA)
			{
				EWA.Mute = false;
				ppplayer.bNoVolumeTips = false;
			}
		}
	}
}

function EWAFastForward(advance)
{
	if (window.delayFFTimerId)
	{
		return;
	}
	var ppplayer = Components.GetObject2("PPPlayer");
	if(ppplayer && !ppplayer.bAlreadyPlaying)
	{
		return;
	}
	var PPP = Components.GetObject2("PPP");
	if(!PPP || (PPP.PlayFileType!=2 && PPP.PlayFileType!=5 && PPP.PlayFileType!=6)) return;
	var EWA= Components.GetObject2("EWA");
	if(!EWA || (EWA.PlayState != 0 && EWA.PlayState != 2 && EWA.PlayState != 3)) return;
	var playcontrol = Components.GetObject2("PPPlayerControl");
	if(playcontrol)
	{
		var pos = EWA.CurrentPosition + (advance?10:-10);
		if(pos<0) pos=0;
		playcontrol.SetPlaySliderValue(pos);
	}

	window.delayFFTimerId = window.setTimeout("realEWAFastForward("+advance+")", 100);
	//快捷键快进设置静音
	var ppplayer = Components.GetObject2("PPPlayer");
	if (ppplayer)
	{
		ppplayer.dragging = true;
		if (!ppplayer.bMute)
		{
			var EWA = Components.GetObject2("EWA");
			if (EWA)
			{
				ppplayer.bNoVolumeTips = true;
				EWA.Mute = true;
			}
		}
	}
	if (window.FFUnMuteId == 0)
	{
		window.FFUnMuteId = window.setInterval("SetFFUnMute();", 500);
	}
}

function PPPSetTrack(track)
{
	var PPP= Components.GetObject2("PPP");
	if(!PPP) return;
	//$("menu_leftTrack").checked=false;
	//$("menu_rightTrack").checked=false;
	//$("menu_stereo").checked=false;
	if(track<0)
	{
		track=-100;
		//$("menu_leftTrack").checked=true;
	}
	else if(track>0)
	{
		track=100;
	//	$("menu_rightTrack").checked=true;
	}
//	else
	//{
	//	$("menu_stereo").checked=true;
	//}
	PPP.Track=track;
}
function Resize(size)
{
	var ppFrame=Components.GetObject2("@pplive.com/PPFrame;1");
	if(ppFrame)
	{	
		ppFrame.ResizerCommand(size,0);
	}
}

function screenShot()
{
	var mframe=Components.GetObject2("mframe");
	if(mframe)
	{	
		mframe.screenShot();
	}
}

function ChangeSkin(id)
{
	var skinMgr = Components.GetObject2("@pplive.com/skinmgr;1");
	if (skinMgr)
	{
		var skinItem = skinMgr.getItemById(id);
		if (skinItem)
		{
			skinMgr.activeSkin = skinItem;
		}
	}
}

function getActiveSkin()
{
	var skinMgr = Components.GetObject2("@pplive.com/skinmgr;1");
	if (skinMgr)
	{
		return skinMgr.activeSkin;
	}
	return null;
}
function getActiveSkinId()
{
	var skinItem = getActiveSkin();
	if (skinItem)
	{
		return skinItem.id;
	}
	return "";
}

function getCityCode()
{
	var channelFactory = Components.GetObject2("@pplive.com/ChannelManagerFactory;1");
	if (channelFactory)
	{
		var channelManager = channelFactory.live();
		if (channelManager)
		{
			return channelManager.cityCode;
		}
	}

	return "1";
}

function ShowAbsolutePath(path)
{
   var s= "";
   var filepath = Components.CreateObject("@pplive.com/filepath;1");
	if (filepath)
	{
		s=filepath.pptvpath+"\\";
		s=s+path;
	}
   return(s);
}

function limitCoreConnection(bConnection)
{
	//将离开选集tab，则开始通知内核放开限速
	var ppframe = Components.GetObject2("PPFrame");
	if (ppframe)
	{
		ppframe.limitConnection = bConnection;
	}
}

function GetDisplayRate(sizeCx1,sizeCy1,sizeCx2,sizeCy2)
{
	var rate;
	var rate1 = sizeCx2*100/sizeCx1;
	var rate2 = sizeCy2*100/sizeCy1;
	rate = rate1;
	if (rate1 > rate2)
	{
		rate = rate2;
	}
	return rate;
}

function AddCurrentChannelToFavirate()
{
	var ppp= Components.GetObject2("PPP");
		if(ppp)
		{
			ppp.AddCurrentChannelToFavirate();
		}
}

function AspectChange(cx,cy)
{
	var mainWnd= Components.GetObject2("@pplive.com/ui/mainwindow;1");
	if(mainWnd)
	{
		var varVideoScan = mainWnd.videoScan;
		if(varVideoScan)
		{
			if(cx==-1&&cy==-1)
			{
				varVideoScan.zoom(4);
			}
			else
			{
				varVideoScan.SetAspectRatio(cx,cy);
			}
		}
	}	
}

function AddFileToFolder()
{
		var ppp= Components.GetObject2("PPP");
		if(ppp)
		{
			var nPlayType = ppp.PlayFileType;
			if(nPlayType!=IPlayerFileType.PLAY_PPVOD) return 0;
			var nChannelId = ppp.ChannelID;
			var nCatalogId = ppp.CatalogID;
			var bstrName = ppp.ChannelName;
			var isVipChannel = ppp.VipChannel;
			var nChannelVtp = ppp.ChannelVtp;
			
			var nHjType = ppp.HjType;
			if((nHjType==2)||(nHjType==98)) //综艺
			{
				var bstrHjName = ppp.HjName;
				var strName = bstrHjName + bstrName;
				bstrName = strName;
			}
			if(nChannelId && bstrName && bstrName.length>0)
		  {
		  	var downloadMgr = Components.GetObject2("@pplive.com/chDownloadMgr;1");
		  	if(downloadMgr)
		  	{
    	  	var nVtp = nChannelVtp & 0x0002;
			    var isvip = isVipChannel?1:0;
				  var param = nVtp|isvip;
				  downloadMgr.downloadChannel(nChannelId,nCatalogId,bstrName,param,nVtp);
		  	}		  	
		  }
		}
		return 1;
}

// 限制矩形区域在显示器内
function ConstrainPosition(screen, left, top, width, height, allowSlop)
{
	var availLeft = left;
	var availTop = top;
	if (allowSlop)
	{
		availLeft = Math.min(availLeft, screen.availLeft + screen.availWidth - 20);
		availLeft = Math.max(availLeft, screen.availLeft - width + 20);
		availTop = Math.min(availTop, screen.availTop + screen.availHeight - 20);
		availTop = Math.max(availTop, screen.availTop - width + 20);
	}
	else
	{
		availLeft = Math.min(availLeft, screen.availLeft + screen.availWidth - width);
		availLeft = Math.max(availLeft, screen.availLeft);
		availTop = Math.min(availTop, screen.availTop + screen.availHeight - height);
		availTop = Math.max(availTop, screen.availTop);
	}
	return {left:availLeft, top:availTop};
}

// 获取"原始分辨率大小播放"策略
// 使用 window 来保存数据
// 返回值：1  自动调整
//         2  半数尺寸(50%)
//         3  适应窗口
//         4  普通尺寸(100%)
//         5  双倍尺寸(200%)
function GetOriginalSizePlayPolicy()
{
	if (window.originalSizePlayPolicy)
	{
		return window.originalSizePlayPolicy;
	}
	window.originalSizePlayPolicy = 3;
	return window.originalSizePlayPolicy;
}

// 设置并应用"原始分辨率大小播放"策略
// argument1:
function SetOriginalSizePlayPolicy()
{
	if (arguments.length >= 1)
	{
		var ospp = arguments[0];
		if (ospp != 1 && ospp != 2 && ospp != 3 && ospp != 4 && ospp != 5)
		{
			return;
		}
		window.originalSizePlayPolicy = ospp;
	}
	var ospp = GetOriginalSizePlayPolicy();
	switch (ospp)
	{
		case 1:
			{
				var ppp = Components.GetObject2("PPP");
				if (ppp && ppp.Oplayer.videoWidth !=0 && ppp.Oplayer.videoHeight !=0)
				{
					if (EwaIsFullScreen() || window.tidyMode)
					{
						window.videoScan.zoom(5);
					}
					else
					{
						if ($("Player").width > ppp.Oplayer.videoWidth*2.0
							&& ($("Player").height - 44) > ppp.Oplayer.videoHeight*2.0)
						{
							window.videoScan.zoom(2);
						}
						else
						{
							window.videoScan.zoom(5);
						}
					}
				}
			}
			break;
		case 2:
			Resize(8);
			window.originalSizePlayPolicy = 2;
			break;
		case 3:
			window.videoScan.zoom(5);
			break;
		case 4:
			Resize(2);
			window.originalSizePlayPolicy = 4;
			break;
		case 5:
			Resize(3);
			window.originalSizePlayPolicy = 5;
			break;
		
	}
}

function showDownloadMgrWnd()
{
	//创建下载管理窗口组件
	var watcher = Components.GetObject2("@pplive.com/window-watcher;1");
	if(!watcher)
	{
		return;
	}
	var downloadMgrWnd = Components.GetObject2("DownloadMgrWnd");
	if(!downloadMgrWnd)
	{
		downloadMgrWnd = watcher.openWindow(0, "DownloadManager.xml", "", "appwindow=1;hidden=1;center=1;");
		Components.RegisterObject("DownloadMgrWnd", downloadMgrWnd);
	}
	else if(downloadMgrWnd.closed)
	{
		downloadMgrWnd = watcher.openWindow(0, "DownloadManager.xml", "", "appwindow=1;hidden=1;center=1;");
	}
	if(downloadMgrWnd.visible == false)
	{
		downloadMgrWnd.visible = true;
	}
	downloadMgrWnd.activated = true;
}

// SIG // Begin signature block
// SIG // MIIVVgYJKoZIhvcNAQcCoIIVRzCCFUMCAQExCzAJBgUr
// SIG // DgMCGgUAMGcGCisGAQQBgjcCAQSgWTBXMDIGCisGAQQB
// SIG // gjcCAR4wJAIBAQQQEODJBs441BGiowAQS9NQkAIBAAIB
// SIG // AAIBAAIBAAIBADAhMAkGBSsOAwIaBQAEFPplppqNn5XC
// SIG // aSeeFH0v+1v/tDIyoIIRWzCCA3owggJioAMCAQICEDgl
// SIG // 1/r4Ya+e9JDnJrXWWtUwDQYJKoZIhvcNAQEFBQAwUzEL
// SIG // MAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJ
// SIG // bmMuMSswKQYDVQQDEyJWZXJpU2lnbiBUaW1lIFN0YW1w
// SIG // aW5nIFNlcnZpY2VzIENBMB4XDTA3MDYxNTAwMDAwMFoX
// SIG // DTEyMDYxNDIzNTk1OVowXDELMAkGA1UEBhMCVVMxFzAV
// SIG // BgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQDEytW
// SIG // ZXJpU2lnbiBUaW1lIFN0YW1waW5nIFNlcnZpY2VzIFNp
// SIG // Z25lciAtIEcyMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB
// SIG // iQKBgQDEtfJSFbyIhmApFkpbL0uRa4eR8zVUWDXq0TZe
// SIG // Yk1SUTRxwntmHYnI3SrEagr2N9mYdJH2kq6wtXaW8alK
// SIG // Y0VHLmsLkk5LK4zuWEqL1AfkGiz4gqpY2c1C8y3Add6N
// SIG // q8eOHZpsTAiVHt7b72fhcsJJwp5gPOHivhajY3hpFHut
// SIG // LQIDAQABo4HEMIHBMDQGCCsGAQUFBwEBBCgwJjAkBggr
// SIG // BgEFBQcwAYYYaHR0cDovL29jc3AudmVyaXNpZ24uY29t
// SIG // MAwGA1UdEwEB/wQCMAAwMwYDVR0fBCwwKjAooCagJIYi
// SIG // aHR0cDovL2NybC52ZXJpc2lnbi5jb20vdHNzLWNhLmNy
// SIG // bDAWBgNVHSUBAf8EDDAKBggrBgEFBQcDCDAOBgNVHQ8B
// SIG // Af8EBAMCBsAwHgYDVR0RBBcwFaQTMBExDzANBgNVBAMT
// SIG // BlRTQTEtMjANBgkqhkiG9w0BAQUFAAOCAQEAUMVLyCSA
// SIG // 3+QNJMLeGrGhAqGmgi0MgxWBNwqCDiywWhdhtdgF/ojb
// SIG // 8ZGRs1YaQKbrkr44ObB1NnQ6mE/kN7qZicqVQh2wuceg
// SIG // jVfg+tVkBEI1TgHRM6IXyE2qJ8fy4YZMAjhNg3jG/FPg
// SIG // 6+AGh92klp5eDJjipb6/goXDYOHfrSjYx6VLZNrHG1u9
// SIG // rDkI1TgioTOLL4qa67wHIT9EQQkHtWUcJLxI00SA66HP
// SIG // yQK0FM9UxxajgFz5eT5dcn2IF54sQ6LKU859PfYqOrhP
// SIG // lAClbQqDXfleU/QYs1cPcMP79a2VoA4X3sQWgGDJDytu
// SIG // hgTx6/R4J9EFxe40W165STLyMzCCA8QwggMtoAMCAQIC
// SIG // EEe/GZXfjVJGQ/fbbUgNMaQwDQYJKoZIhvcNAQEFBQAw
// SIG // gYsxCzAJBgNVBAYTAlpBMRUwEwYDVQQIEwxXZXN0ZXJu
// SIG // IENhcGUxFDASBgNVBAcTC0R1cmJhbnZpbGxlMQ8wDQYD
// SIG // VQQKEwZUaGF3dGUxHTAbBgNVBAsTFFRoYXd0ZSBDZXJ0
// SIG // aWZpY2F0aW9uMR8wHQYDVQQDExZUaGF3dGUgVGltZXN0
// SIG // YW1waW5nIENBMB4XDTAzMTIwNDAwMDAwMFoXDTEzMTIw
// SIG // MzIzNTk1OVowUzELMAkGA1UEBhMCVVMxFzAVBgNVBAoT
// SIG // DlZlcmlTaWduLCBJbmMuMSswKQYDVQQDEyJWZXJpU2ln
// SIG // biBUaW1lIFN0YW1waW5nIFNlcnZpY2VzIENBMIIBIjAN
// SIG // BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqcqypMzN
// SIG // IK8KfYmsh3XwtE7x38EPv2dhvaNkHNq7+cozq4QwiVh+
// SIG // jNtr3TaeD7/R7Hjyd6Z+bzy/k68Numj0bJTKvVItq0g9
// SIG // 9bbVXV8bAp/6L2sepPejmqYayALhf0xS4w5g7EAcfrkN
// SIG // 3j/HtN+HvV96ajEuA5mBE6hHIM4xcw1XLc14NDOVEpkS
// SIG // ud5oL6rm48KKjCrDiyGHZr2DWFdvdb88qiaHXcoQFTyf
// SIG // hOpUwQpuxP7FSt25BxGXInzbPifRHnjsnzHJ8eYiGdvE
// SIG // s0dDmhpfoB6Q5F717nzxfatiAY/1TQve0CJWqJXNroh2
// SIG // ru66DfPkTdmg+2igrhQ7s4fBuwIDAQABo4HbMIHYMDQG
// SIG // CCsGAQUFBwEBBCgwJjAkBggrBgEFBQcwAYYYaHR0cDov
// SIG // L29jc3AudmVyaXNpZ24uY29tMBIGA1UdEwEB/wQIMAYB
// SIG // Af8CAQAwQQYDVR0fBDowODA2oDSgMoYwaHR0cDovL2Ny
// SIG // bC52ZXJpc2lnbi5jb20vVGhhd3RlVGltZXN0YW1waW5n
// SIG // Q0EuY3JsMBMGA1UdJQQMMAoGCCsGAQUFBwMIMA4GA1Ud
// SIG // DwEB/wQEAwIBBjAkBgNVHREEHTAbpBkwFzEVMBMGA1UE
// SIG // AxMMVFNBMjA0OC0xLTUzMA0GCSqGSIb3DQEBBQUAA4GB
// SIG // AEpr+epYwkQcMYl5mSuWv4KsAdYcTM2wilhu3wgpo17I
// SIG // ypMT5wRSDe9HJy8AOLDkyZNOmtQiYhX3PzchT3AxgPGL
// SIG // OIez6OiXAP7PVZZOJNKpJ056rrdhQfMqzufJ2V7duyuF
// SIG // PrWdtdnhV/++tMV+9c8MnvCX/ivTO1IbGzgn9z9KMIIE
// SIG // /DCCBGWgAwIBAgIQZVIm4bIuGOFZDymFrCLnXDANBgkq
// SIG // hkiG9w0BAQUFADBfMQswCQYDVQQGEwJVUzEXMBUGA1UE
// SIG // ChMOVmVyaVNpZ24sIEluYy4xNzA1BgNVBAsTLkNsYXNz
// SIG // IDMgUHVibGljIFByaW1hcnkgQ2VydGlmaWNhdGlvbiBB
// SIG // dXRob3JpdHkwHhcNMDkwNTIxMDAwMDAwWhcNMTkwNTIw
// SIG // MjM1OTU5WjCBtjELMAkGA1UEBhMCVVMxFzAVBgNVBAoT
// SIG // DlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZWZXJpU2ln
// SIG // biBUcnVzdCBOZXR3b3JrMTswOQYDVQQLEzJUZXJtcyBv
// SIG // ZiB1c2UgYXQgaHR0cHM6Ly93d3cudmVyaXNpZ24uY29t
// SIG // L3JwYSAoYykwOTEwMC4GA1UEAxMnVmVyaVNpZ24gQ2xh
// SIG // c3MgMyBDb2RlIFNpZ25pbmcgMjAwOS0yIENBMIIBIjAN
// SIG // BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvmcdtGCq
// SIG // EElvVhd8Zslehg3V8ayncYOOi4n4iASJFQa6LYQhleTR
// SIG // nFBM+9IivdrysjU7Ho/DCfv8Ey5av4l8PTslHvbzWHuc
// SIG // 9AG1xgq4gM6+J3RhZydNauXsgWFYeaPgFxASFSew4U00
// SIG // fytHIES53mYkZorNT7ofxTjIVJDhcvYZZnVquUlozzh5
// SIG // DaowqNssYEie16oUAamD1ziRMDkTlgM6fEBUtq3gLxuD
// SIG // 3KgRUj4Cs9cr/SG2p1yjDwupphBQDjQuTafOyV4l1Iy8
// SIG // 8258KbwBXfwxh1rVjIVnWIgZoL818OoroyHnkPaD5ajt
// SIG // YHhee2CD/VcLXUENY1Rg1kMh7wIDAQABo4IB2zCCAdcw
// SIG // EgYDVR0TAQH/BAgwBgEB/wIBADBwBgNVHSAEaTBnMGUG
// SIG // C2CGSAGG+EUBBxcDMFYwKAYIKwYBBQUHAgEWHGh0dHBz
// SIG // Oi8vd3d3LnZlcmlzaWduLmNvbS9jcHMwKgYIKwYBBQUH
// SIG // AgIwHhocaHR0cHM6Ly93d3cudmVyaXNpZ24uY29tL3Jw
// SIG // YTAOBgNVHQ8BAf8EBAMCAQYwbQYIKwYBBQUHAQwEYTBf
// SIG // oV2gWzBZMFcwVRYJaW1hZ2UvZ2lmMCEwHzAHBgUrDgMC
// SIG // GgQUj+XTGoasjY5rw8+AatRIGCx7GS4wJRYjaHR0cDov
// SIG // L2xvZ28udmVyaXNpZ24uY29tL3ZzbG9nby5naWYwHQYD
// SIG // VR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMDMDQGCCsG
// SIG // AQUFBwEBBCgwJjAkBggrBgEFBQcwAYYYaHR0cDovL29j
// SIG // c3AudmVyaXNpZ24uY29tMDEGA1UdHwQqMCgwJqAkoCKG
// SIG // IGh0dHA6Ly9jcmwudmVyaXNpZ24uY29tL3BjYTMuY3Js
// SIG // MCkGA1UdEQQiMCCkHjAcMRowGAYDVQQDExFDbGFzczND
// SIG // QTIwNDgtMS01NTAdBgNVHQ4EFgQUl9BrqCZwyKE/lB8I
// SIG // LcQ1m6ShHvIwDQYJKoZIhvcNAQEFBQADgYEAiwPA3ZTY
// SIG // QaJhabAVqHjHMMaQPH5C9yS25INzFwR/BBCcoeL6gS/r
// SIG // wMpE53LgULZVECCDbpaS5JpRarQ3MdylLeuMAMcdT+dN
// SIG // MrqF+E6++mdVZfBqvnrKZDgaEBB4RXYx84Z6Aw9gwrNd
// SIG // nfaLZnaCG1nhg+W9SaU4VuXeQXcOWA8wggURMIID+aAD
// SIG // AgECAhBtUn9NfWwaK6fvgdUMiddlMA0GCSqGSIb3DQEB
// SIG // BQUAMIG2MQswCQYDVQQGEwJVUzEXMBUGA1UEChMOVmVy
// SIG // aVNpZ24sIEluYy4xHzAdBgNVBAsTFlZlcmlTaWduIFRy
// SIG // dXN0IE5ldHdvcmsxOzA5BgNVBAsTMlRlcm1zIG9mIHVz
// SIG // ZSBhdCBodHRwczovL3d3dy52ZXJpc2lnbi5jb20vcnBh
// SIG // IChjKTA5MTAwLgYDVQQDEydWZXJpU2lnbiBDbGFzcyAz
// SIG // IENvZGUgU2lnbmluZyAyMDA5LTIgQ0EwHhcNMDkxMTE5
// SIG // MDAwMDAwWhcNMTIxMTE4MjM1OTU5WjCBzjELMAkGA1UE
// SIG // BhMCQ04xETAPBgNVBAgTCFNoYW5naGFpMREwDwYDVQQH
// SIG // EwhTaGFuZ2hhaTEbMBkGA1UEChQSUFBMaXZlIENvcnBv
// SIG // cmF0aW9uMT4wPAYDVQQLEzVEaWdpdGFsIElEIENsYXNz
// SIG // IDMgLSBNaWNyb3NvZnQgU29mdHdhcmUgVmFsaWRhdGlv
// SIG // biB2MjEfMB0GA1UECxQWUHJvZHVjdCBQbGFubmluZyBE
// SIG // ZXB0LjEbMBkGA1UEAxQSUFBMaXZlIENvcnBvcmF0aW9u
// SIG // MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDY7Kff
// SIG // TNpvjGy6zGck0u1/S+B50zuxRF0HrIlPfcpSGmsQyfzm
// SIG // b2eigTz0KuN+palZSdpx0amg9gD+ANFSNo9uqfk1PLeP
// SIG // V7187RIh4taAGUnYROqkPr9kVAsU/SepgjYLVAU46+Bu
// SIG // FtDmCaenpb6rqE+0Y6AV50Rc3iBA0rHvawIDAQABo4IB
// SIG // gzCCAX8wCQYDVR0TBAIwADAOBgNVHQ8BAf8EBAMCB4Aw
// SIG // RAYDVR0fBD0wOzA5oDegNYYzaHR0cDovL2NzYzMtMjAw
// SIG // OS0yLWNybC52ZXJpc2lnbi5jb20vQ1NDMy0yMDA5LTIu
// SIG // Y3JsMEQGA1UdIAQ9MDswOQYLYIZIAYb4RQEHFwMwKjAo
// SIG // BggrBgEFBQcCARYcaHR0cHM6Ly93d3cudmVyaXNpZ24u
// SIG // Y29tL3JwYTATBgNVHSUEDDAKBggrBgEFBQcDAzB1Bggr
// SIG // BgEFBQcBAQRpMGcwJAYIKwYBBQUHMAGGGGh0dHA6Ly9v
// SIG // Y3NwLnZlcmlzaWduLmNvbTA/BggrBgEFBQcwAoYzaHR0
// SIG // cDovL2NzYzMtMjAwOS0yLWFpYS52ZXJpc2lnbi5jb20v
// SIG // Q1NDMy0yMDA5LTIuY2VyMB8GA1UdIwQYMBaAFJfQa6gm
// SIG // cMihP5QfCC3ENZukoR7yMBEGCWCGSAGG+EIBAQQEAwIE
// SIG // EDAWBgorBgEEAYI3AgEbBAgwBgEBAAEB/zANBgkqhkiG
// SIG // 9w0BAQUFAAOCAQEAEHyS6zHfeAr7VXV0+4exGGIaodyt
// SIG // snOwewImElZdtDXV0P9r4B6gp1Ej1ZT8Ddco099Xc7NE
// SIG // e7gyfzCQh27Uq6DSVQP0P9zBI2VgwWaOLweplMHFqKrD
// SIG // q0DXzRAsXiYCu15ugktqWBRVhsOCrNFPcYAiEHhMeRJY
// SIG // 1p5pA+TyXSs2X5AyL1zfpaqrDfJKmhspWabkMbjyLWG9
// SIG // jkQv7K4rviPg//9QfzZoYG3cJBMDqLC3KsSFXs6GNzXo
// SIG // 7EDYhzgJFjpalJUV0n7TL+aPFgRY6/lG3UYPZtsRtGBI
// SIG // W2frpPZy0ww0vcTMzXYL+2TGyka40qCWF3XUw14+znhe
// SIG // yMNA5TGCA2cwggNjAgEBMIHLMIG2MQswCQYDVQQGEwJV
// SIG // UzEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xHzAdBgNV
// SIG // BAsTFlZlcmlTaWduIFRydXN0IE5ldHdvcmsxOzA5BgNV
// SIG // BAsTMlRlcm1zIG9mIHVzZSBhdCBodHRwczovL3d3dy52
// SIG // ZXJpc2lnbi5jb20vcnBhIChjKTA5MTAwLgYDVQQDEydW
// SIG // ZXJpU2lnbiBDbGFzcyAzIENvZGUgU2lnbmluZyAyMDA5
// SIG // LTIgQ0ECEG1Sf019bBorp++B1QyJ12UwCQYFKw4DAhoF
// SIG // AKBwMBAGCisGAQQBgjcCAQwxAjAAMBkGCSqGSIb3DQEJ
// SIG // AzEMBgorBgEEAYI3AgEEMBwGCisGAQQBgjcCAQsxDjAM
// SIG // BgorBgEEAYI3AgEVMCMGCSqGSIb3DQEJBDEWBBTjKndj
// SIG // HzCcfmB43j2a0cBLNmCvUTANBgkqhkiG9w0BAQEFAASB
// SIG // gMuSI7fc5iIpsanXCpHjk3bc+LF4cUpdtyVm8cwIZGkf
// SIG // l6spqsqCo7QVtpUpE9G8uebSuEsd212fiOAs0d43RC6y
// SIG // jc4vaS3N2u2d18xiFAXG3c8meNdL/0AUp68JUvYrvRhz
// SIG // yQv2a2xM6s7xDIJywK19W8q+cIR7EcD+0kHUxHY0oYIB
// SIG // fzCCAXsGCSqGSIb3DQEJBjGCAWwwggFoAgEBMGcwUzEL
// SIG // MAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJ
// SIG // bmMuMSswKQYDVQQDEyJWZXJpU2lnbiBUaW1lIFN0YW1w
// SIG // aW5nIFNlcnZpY2VzIENBAhA4Jdf6+GGvnvSQ5ya11lrV
// SIG // MAkGBSsOAwIaBQCgXTAYBgkqhkiG9w0BCQMxCwYJKoZI
// SIG // hvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0xMTA5MDkwODEx
// SIG // NDdaMCMGCSqGSIb3DQEJBDEWBBQtyndUJ7pTAYi8vGp1
// SIG // pqT9S5WxbDANBgkqhkiG9w0BAQEFAASBgHsdcz70zegX
// SIG // tRfdWwlCHVJ4k6f75D9xBK1xMFvHoZBMbJlCG/oZ4eeS
// SIG // iFarxMGvPXz37vExw03r/gVkYI4KSlC0ekrkjAVukiwY
// SIG // 7bHwrrxrRpiO6nyc3eqXAaCC7dTsQHXjBxzw0fG3g7IZ
// SIG // Rwgw1jgicFjO2hLRhn/Vzu7ZpsXt
// SIG // End signature block
