<?xml version="1.0" encoding="utf-8"?>
<window left="0" top="0" width="244" height="226" resizeMargins="0,0,0,0" bottomRightCorner="0,0" maximizable="false" onload="windowOnLoad();" title="视频小窗" onshow="if(!window.isOpen){ window.setTimeout('if(!window.isOpen)window.visible=false;', 5);}" onclose="if(!window.canClose){window.parent.execScript('exitMiniPlayer(false);');return false;}">
	<script src="common.js" />
	<script>
	<![CDATA[
		function windowOnLoad()
		{
			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.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);
				}
			}
			var registry = Components.CreateObject("@pplive.com/registry;1");
			if (registry && registry.open(registry.HKCU, "Software\\PPLive\\PPTV\\MiniPlayMode",IRegistry.KEY_READ))
			{
				var miniplayleft=0;
				var miniplaytop=0;
				miniplayleft = registry.readDWORD("miniplayleft");
				miniplaytop = registry.readDWORD("miniplaytop");
				window.moveTo(miniplayleft,miniplaytop);
			}
			else
			{
				moveToParentSouthEastCorner();
			}
		}
		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 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 = "";
			}
			$("mute").checked = EWA.Mute;

		}
		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);
		}
	]]>
	</script>
	<subwindow left="0" top="0" width="244" height="226" backgroundColor="#000000" passThrough="false" onmousedown="if(event.button == IDOMEvent.eLeftButton) window.size('move');">
		<!-- 背景图 -->
		<image left="0" top="0" width="244" height="26" src="small\frame_title.png" stretchMode="ninegrid" nineGridMargins="2,0,2,26"/>
		<image left="242" top="26" width="2" height="198" src="small\frame_r.png" stretchMode="stretch"/>
		<image left="0" top="224" width="244" height="2" src="small\frame_bottom.png" stretchMode="ninegrid" nineGridMargins="2,0,2,2"/>
		<image left="0" top="26" width="2" height="198" src="small\frame_l.png" stretchMode="stretch"/>
		<image left="2" top="204" width="240" height="20" src="small\control_bg.png" 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" value="" textAlignment="left vcenter" textOverflow="ellipsis" passThrough="true" foregroundColor="#b3b2b2"/>
		<button left="219" top="1" width="24" height="24" 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" contractId="" useService="true" visible="true"/> <!-- @pplive.com/PPFrame;1 -->
		<button id="playorpause" left="2" top="204" width="24" height="20" 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" image="small\volume.png" hoverImage="small\volume_hover.png" downImage="small\volume_down.png" checkImage="small\volume1.png" checkHoverImage="small\volume1_hover.png" checkDownImage="small\volume1_down.png" checked="false" tooltip="静音" checkTooltip="取消静音" onclick="EwaChangeMute();updatePlayState();"/>
		<label id="status" left="100" top="204" width="137" height="20" value="00:06:00/00:45:15"  textAlignment="right vcenter" foregroundColor="#b3b2b2"/>
	</subwindow>
</window>