<?xml version="1.0" encoding="utf-8"?>
<window left="0" top="0" width="244" height="226" minWidth="244" minHeight="226" maxWidth="484" maxHeight="406" resizeMargins="2,2,2,2" bottomRightCorner="0,0" maximizable="false" onload="windowOnLoad();" title="视频小窗" onshow="if(!window.isOpen){ window.setTimeout('if(!window.isOpen)window.visible=false;', 5);}" onhide="if (window.volDlg){window.volDlg.close();window.volDlg=null;}if(event.status==1) {return false;}" onclose="if(!window.canClose){window.parent.execScript('exitMiniPlayer(false);');return false;}" onunload="windowOnunload();">
	<script src="common.js" />
	<script>
	<![CDATA[
		function windowOnLoad()
		{
			window.checkVolumeHoverTimeId=0;
			window.hover_mute=false;
			window.hover_mute2=false;
			window.hover_mute3=false;
			window.hover_mute4=false;
			window.hover_muteplus=false;
			window.hover_unmute=false;
			window.hover_volpop=false;

			window.volDlg = null;
			window.canClose = false;
			window.isOpen = false;
			window.updateInterval = 0;
			//打开窗口边框吸附
			window.setAdsorb=true;
			window.openMiniPlayer = function()
			{
				if ($("Player").contractId.length <= 0)
				{
					$("Player").setContractId("@pplive.com/PPFrame;1", true);
				}
				else
				{
					$("Player").rob();
				}
				updatePlayState();
				window.updateInterval = window.setInterval("updatePlayState();", 500);
				window.isOpen = true;
				window.visible = true;
			}
			window.updateMute =function()
			{
				var EWA = Components.GetObject("EWA");
				if(!EWA) { return; }
				var mute = EWA.Mute;
				var vol = EWA.Volume;
				SetMute(vol,mute);
				if (window.volDlg)
				{
					window.volDlg.OnChangeMute(EWA.Mute);
				}
			}
			window.directClose = function()
			{
				window.canClose = true;
				window.close();
			}
			window.closeMiniPlayer = function()
			{
				if (window.updateInterval)
				{
					window.clearInterval(window.updateInterval);
					window.updateInterval = 0;
				}
	
				window.visible = false;
				window.isOpen = false;

				var registry = Components.CreateObject("@pplive.com/registry;1");
				if (registry && registry.create(registry.HKCU, "Software\\PPLive\\PPTV\\MiniPlayMode"))
				{
					registry.writeDWORD("miniplayleft",window.screenLeft);
					registry.writeDWORD("miniplaytop",window.screenTop);
					registry.writeDWORD("miniplaywidth",window.outerWidth);
					registry.writeDWORD("miniplayheight",window.outerHeight);
				}
			}
			var registry = Components.CreateObject("@pplive.com/registry;1");
			if (registry && registry.open(registry.HKCU, "Software\\PPLive\\PPTV\\MiniPlayMode",IRegistry.KEY_READ))
			{
				var miniplayleft = registry.read("miniplayleft");
				var miniplaytop = registry.read("miniplaytop");
				var miniplaywidth = registry.read("miniplaywidth");
				var miniplayheight = registry.read("miniplayheight");
				var screen = window.parent.screen;
				miniplayleft = Math.min(Math.max(miniplayleft, screen.availLeft), screen.availLeft+screen.availWidth);
				miniplaytop = Math.min(Math.max(miniplaytop, screen.availTop), screen.availTop + screen.availHeight);
				miniplaywidth = Math.min(Math.max(244, miniplaywidth), 484);
				miniplayheight = Math.min(Math.max(226, miniplayheight), 406);

				if (miniplayleft + miniplaywidth > screen.availLeft + screen.availWidth)
				{
					miniplayleft = screen.availLeft + screen.availWidth - miniplaywidth;
				}
				if (miniplaytop + miniplayheight > screen.availTop + screen.availHeight)
				{
					miniplaytop = screen.availTop + screen.availHeight - miniplayheight;
				}
				
				window.moveSizeTo(miniplayleft,miniplaytop, miniplaywidth, miniplayheight);
			}
			else
			{
				moveToParentSouthEastCorner();
			}
		}
		function windowOnunload()
		{
			if (window.isOpen)
			{
				var registry = Components.CreateObject("@pplive.com/registry;1");
				if (registry && registry.create(registry.HKCU, "Software\\PPLive\\PPTV\\MiniPlayMode"))
				{
					registry.writeDWORD("miniplayleft",window.screenLeft);
					registry.writeDWORD("miniplaytop",window.screenTop);
				}
			}
		}
		function moveToParentSouthEastCorner()
		{
			if(!window.parent)
			{
				return;
			}
			window.moveTo(window.parent.screenLeft+window.parent.outerWidth - window.outerWidth - 20,
					window.parent.screenTop+window.parent.outerHeight - window.outerHeight);
		}
		function SetMute(vol,bMute)
		{
			$("mute").visible = false;
			$("mute2").visible = false;
			$("mute3").visible = false;
			$("mute4").visible = false;
			$("muteplus").visible = false;
			if (bMute)
			{
				$("unmute").visible = true;
				return ;
			}
			else
			{
				$("unmute").visible = false;
			}
			
			if (vol <= 0)
			{
				$("mute").visible = true;
			}
			else if(vol > 0 && vol <= 35)
			{
				$("mute2").visible = true;
			}
			else if (vol > 35 && vol <= 80) 
			{
				$("mute3").visible = true;
			}
			else if (vol > 80 && vol <= 100)
			{
				$("mute4").visible = true;
			}
			else
			{
				$("muteplus").visible = true;
			}
		}
		function ChangeMute()
		{
			var EWA = Components.GetObject("EWA");
			if(!EWA) { return; }
			EWA.Mute = !EWA.Mute;
			if(window && window.volDlg)
			{
				window.volDlg.OnChangeMute(EWA.Mute);
			}
		}
		function updatePlayState()
		{
			var EWA = Components.GetObject("EWA");
			if(!EWA) { return; }
			var playState = EWA.State;
			var title = "";
			switch(playState)
			{
				case IPlayerState.pppBuffering: title = "正在缓冲:";  break;
				case IPlayerState.pppReady:     break;
				case IPlayerState.pppPlay:      title = "正在播放:"; $("playorpause").checked = true; break;
				case IPlayerState.pppPause:     title = "已暂停:";   $("playorpause").checked = false;  break;
				case IPlayerState.pppStop:      title = "已停止:";   $("playorpause").checked = false;  break;
				case IPlayerState.pppMediaEnd:  title = "已完成:";   $("playorpause").checked = false;   break;
			}
			title += EWA.ChannelName;
			$("playTitle").value=title;

			var duration = EWA.Duration;
			if (duration > 0)
			{
				var current = EWA.Position;
				var status = time_format(current);
				status += "/";
				status += time_format(duration);
				$("status").value = status;
			}
			else
			{
				$("status").value = "";
			}
			var mute = EWA.Mute;
			var vol = EWA.Volume;
			SetMute(vol,mute);
			//var ppplayercontrol = Components.GetObject2("PPPlayerControl");
			//if (ppplayercontrol)
			//{
			//	ppplayercontrol.OnUpdateMute();
			//}
		}
		function aa(i){
			return i > 9 ? i : '0' + i;
		}
		function time_format(sec){
			var h = Math.floor(sec / 3600);
			var m = Math.floor(sec % 3600 / 60);
			var s = sec % 60;
			return [aa(h), aa(m), aa(s)].join(':');
		}
		function PPLState(i)
		{
		    var PPLState = Components.GetObject2('@pplive.com/PPLStat;1');
		    if(PPLState)PPLState.PPTVStartTime(i);
		}
		function closeVolumePopDlg()
		{
			if (window.volDlg && window.checkVolumeHoverTimeId)
			{
				window.volDlg.close();
				window.volDlg=null;
				window.checkVolumeHoverTimeId=0;
			}
		}
		function checkVolumeHover()
		{
			if(this && this.nodename && this.nodename=="button" && !this.visible)
			{
				//过渡状态
				return;
			}

			//window.volDlg
			var mute = window.hover_mute;
			var mute2 = window.hover_mute2;
			var mute3 = window.hover_mute3;
			var mute4 = window.hover_mute4;
			var unmute = window.hover_muteplus;
			var muteplus = window.hover_unmute;
			var volpop = window.hover_volpop;
			if(mute || mute2 || mute3 || mute4 || unmute || muteplus || volpop)
			{
				if(window.checkVolumeHoverTimeId)
				{
					window.clearTimeout(window.checkVolumeHoverTimeId);
					window.checkVolumeHoverTimeId=0;
				}
				if(window.volDlg)
				{
					window.volDlg.visible = true;
					return;
				}
				if(!this) return;
				window.volDlg = window.open("playcontrol\\VolumePopDlgMini.xml","","owner=1");
				window.volDlg.moveTo(this.offsetLeft+window.screenLeft+this.width/2-window.volDlg.outerWidth/2,window.screenTop-window.volDlg.outerHeight + this.offsetTop + 2);
				window.volDlg.visible = true;
			}
			else
			{
				window.checkVolumeHoverTimeId = window.SetTimeout("closeVolumePopDlg();",100);
			}
		}
	]]>
	</script>
	<subwindow left="0" top="0" width="244" height="226" backgroundColor="#000000" passThrough="false" onmousedown="if(event.button == IDOMEvent.eLeftButton) window.size('move');" horizontalAlignment="stretch" verticalAlignment="stretch">
		<!-- 背景图 -->
		<image left="0" top="0" width="244" height="26" src="small\frame_title.png" horizontalAlignment="stretch" verticalAlignment="top" stretchMode="ninegrid" nineGridMargins="2,0,2,26"/>
		<image left="242" top="26" width="2" height="198" src="small\frame_r.png" horizontalAlignment="right" verticalAlignment="stretch" stretchMode="stretch"/>
		<image left="0" top="224" width="244" height="2" src="small\frame_bottom.png" horizontalAlignment="stretch" verticalAlignment="bottom" stretchMode="ninegrid" nineGridMargins="2,0,2,2"/>
		<image left="0" top="26" width="2" height="198" src="small\frame_l.png" horizontalAlignment="left" verticalAlignment="stretch" stretchMode="stretch"/>
		<image left="2" top="204" width="240" height="20" src="small\control_bg.png" horizontalAlignment="stretch" verticalAlignment="bottom" stretchMode="stretch"/>
		<!-- 控件 -->
		<button left="3" top="6" width="16" height="15" image="small\tomain.png" hoverImage="small\tomain_hover.png" downImage="small\tomain_down.png" onclick="window.parent.execScript('exitMiniPlayer(true);');PPLState(30);" tooltip="回大窗播放"/>
		<label id="playTitle" left="24" top="0" width="195" height="26" horizontalAlignment="stretch" value="" textAlignment="left vcenter" textOverflow="ellipsis" passThrough="true" foregroundColor="#b3b2b2"/>
		<button left="219" top="1" width="24" height="24" horizontalAlignment="right" verticalAlignment="top" image="close.png" hoverImage="close_hover.png" downImage="close_down.png" onclick="window.parent.execScript('exitMiniPlayer(false);');PPLState(29);" tooltip="关闭小窗"/>
		<widget id="Player" left="2" top="26" width="240" height="180" horizontalAlignment="stretch" verticalAlignment="stretch" contractId="" useService="true" visible="true"/> <!-- @pplive.com/PPFrame;1 -->
		<button id="playorpause" left="2" top="204" width="24" height="20" horizontalAlignment="left" verticalAlignment="bottom" image="small\play.png" hoverImage="small\play_hover.png" downImage="small\play_down.png" checkImage="small\pause.png" checkHoverImage="small\pause_hover.png" checkDownImage="small\pause_down.png" checked="false"  tooltip="播放" checkTooltip="暂停" onclick="EwaPlayOrPause();updatePlayState();"/>

		<button id="mute" left="25" top="204" width="24" height="20" horizontalAlignment="left" verticalAlignment="bottom" image="small\small_btn_volume_0_normal.png" hoverImage="small\small_btn_volume_0_hover.png" downImage="small\small_btn_volume_0_down.png" tooltip="取消静音" onclick="ChangeMute();updatePlayState();" onmouseover="window.hover_mute=true;checkVolumeHover.call(this);" onmouseout="window.hover_mute=false;checkVolumeHover.call(this);"/>
		<button id="mute2" left="25" top="204" width="24" height="20" horizontalAlignment="left" verticalAlignment="bottom" image="small\small_btn_volume_1_normal.png" hoverImage="small\small_btn_volume_1_hover.png" downImage="small\small_btn_volume_1_down.png" tooltip="静音" onclick="ChangeMute();updatePlayState();" onmouseover="window.hover_mute2=true;checkVolumeHover.call(this);" onmouseout="window.hover_mute2=false;checkVolumeHover.call(this);"/>
		<button id="mute3" left="25" top="204" width="24" height="20" horizontalAlignment="left" verticalAlignment="bottom" image="small\small_btn_volume_2_normal.png" hoverImage="small\small_btn_volume_2_hover.png" downImage="small\small_btn_volume_2_down.png" tooltip="静音" onclick="ChangeMute();updatePlayState();" onmouseover="window.hover_mute3=true;checkVolumeHover.call(this);" onmouseout="window.hover_mute3=false;checkVolumeHover.call(this);"/>
		<button id="mute4" left="25" top="204" width="24" height="20" horizontalAlignment="left" verticalAlignment="bottom" image="small\small_btn_volume_3_normal.png" hoverImage="small\small_btn_volume_3_hover.png" downImage="small\small_btn_volume_3_down.png" tooltip="静音" onclick="ChangeMute();updatePlayState();" onmouseover="window.hover_mute4=true;checkVolumeHover.call(this);" onmouseout="window.hover_mute4=false;checkVolumeHover.call(this);"/>
		<button id="muteplus" left="25" top="204" width="24" height="20" horizontalAlignment="left" verticalAlignment="bottom" image="small\small_btn_volume_4_normal.png" hoverImage="small\small_btn_volume_4_hover.png" downImage="small\small_btn_volume_4_down.png" tooltip="静音" onclick="ChangeMute();updatePlayState();" onmouseover="window.hover_muteplus=true;checkVolumeHover.call(this);" onmouseout="window.hover_muteplus=false;checkVolumeHover.call(this);"/>
		<button id="unmute" left="25" top="204" width="24" height="20" horizontalAlignment="left" verticalAlignment="bottom" image="small\small_btn_volume_0_normal.png" hoverImage="small\small_btn_volume_0_hover.png" downImage="small\small_btn_volume_0_down.png" tooltip="取消静音" onclick="ChangeMute();updatePlayState();" onmouseover="window.hover_unmute=true;checkVolumeHover.call(this);" onmouseout="window.hover_unmute=false;checkVolumeHover.call(this);"/>

		<label id="status" left="100" top="204" width="137" horizontalAlignment="right" verticalAlignment="bottom" height="20" value="00:00:00/00:00:00"  textAlignment="right vcenter" foregroundColor="#b3b2b2"/>
	</subwindow>
</window>