<%@ Page PathInChannel="play.aspx" RunAt="Execute" %>
<%
	if (String.IsNullOrEmpty(Request.QueryString["ID"]))
		return null;
%>
<script runat="server">
string BuildCondition()
{
	StringBuilder result = new StringBuilder();
	
	string[] ids = Request.QueryString["ID"].Split('|');
	foreach (string id in ids)
	{
		if (result.Length == 0)
			result.Append(IlgharSite.M0013.Alias.Music.InnerID + "=" + id);
		else
			result.Append(" or " + IlgharSite.M0013.Alias.Music.InnerID + "=" + id);
	}
	return result.ToString();
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- TemplateInfo codeOutsideHTMLIsLocked="true" -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>连续播放 - <%=ChannelName%> - <%=SiteName%></title>
<ilghar:Comment><link rel="stylesheet" type="text/css" href="S01/CHS/css/common.css" /></ilghar:Comment>
<link rel="stylesheet" type="text/css" href="<%=CssPath%>common.css" />
<script type="text/javascript" src="/common/ajax.js"></script>
<script type="text/javascript" src="/common/equalcols.js"></script>
<script type="text/javascript" src="/common/utility.js"></script>
<script type="text/javascript">
var _players = new Array();
var _musics = new Array();
var _index = -1;
var _playerID = null;

function OnTimer()
{
	if (document.getElementById("IlgharMediaPlayer") != null)
	{
		var player = document.getElementById("IlgharMediaPlayer");
		if (player.PlayState == 1 || player.PlayState == 10)
			PlayNext();
	}
	else if (document.getElementById("IlgharRealPlayer") != null)
	{
		var player = document.getElementById("IlgharRealPlayer");
		if (player.GetPlayState() == 0)
			PlayNext();
	}
	else
	{
		return;
	}
		
	setTimeout("OnTimer()", 1000);
}

function Play(id)
{
	if (_index != -1)
		document.getElementById("TR" + _index).className = "";
	
	_index = id;
	if (_index >= _musics.length)
		_index = 0;

	document.getElementById("TR" + _index).className = "Select";
	
	var same = true;
	if (_playerID == null || _playerID != _musics[_index].PlayerID)
	{
		_playerID = _musics[_index].PlayerID;

		for (var i = 0; i < _players.length; i++)
		{
			if (_playerID == _players[i].ID)
			{
				var jsCode = UrlDecode(_players[i].Code) + "<script>WritePlayer(parent._musics[parent._index].URL, null, null, null, parent.Player);<" + "/script>";
				var jsIframe = document.createElement("iframe");
				jsIframe.style.display = "none";
				document.body.appendChild(jsIframe);
				with(window.frames[window.frames.length - 1])
				{
					document.open();
					document.write(jsCode);
					document.close();
				}
				document.body.removeChild(jsIframe);
				break;
			}
		}

		same = false;
	}
	
	if (document.getElementById("IlgharMediaPlayer") != null)
	{
		var player = document.getElementById("IlgharMediaPlayer");
		if (same)
			player.URL = _musics[_index].URL;
	
		player.settings.playCount = 1;			
	}
	else if (document.getElementById("IlgharRealPlayer") != null)
	{
		var player = document.getElementById("IlgharRealPlayer");
		if (same)
			player.SetSource(_musics[_index].URL);
		player.SetLoop(false);
 	}
	
	document.getElementById("MusicName").innerHTML = _musics[_index].Name;

	if (_musics[_index].Lyric != null)
	{
		document.getElementById("Lyric").innerHTML = UrlDecode(_musics[_index].Lyric).replace(/\r\n/g, "<br>");
	}
	else
	{
		document.getElementById("Lyric").innerHTML = "";
	}

	var action1 = "<button onclick=\"Up(this, " + _musics[_index].InnerID + ")\">顶 <span>" + _musics[_index].Up + "</span></button>";
	action1 += "<button onclick=\"Down(this, " + _musics[_index].InnerID + ")\">踩 <span>" + _musics[_index].Down + "</span></button>";
	document.getElementById("Action1").innerHTML = action1;
	
	var action2 = "<button onclick=\"ReportMusicError(this, " + _musics[_index].InnerID + ")\">歌曲有错</button>";
	if (_musics[_index].Lyric != null)
		action2 += "<button onclick=\"ReportLyricError(this, " + _musics[_index].InnerID + ")\">歌词有错</button>";
	document.getElementById("Action2").innerHTML = action2;
	
	_ajax.Post("/ws.aspx?Object=Music&Operation=IncrementHitCount&ID=" + _musics[_index].InnerID, null, null);

	setTimeout("OnTimer()", 1000);
}

function PlayNext()
{
	Play(_index + 1);
}

function PlayPrev()
{
	Play(_index - 1);
}

function Up(obj, id)
{
	_ajax.Post("/ws.aspx?Object=Music&Operation=IncrementUp&ID=" + id, null, null);
	obj.disabled = true;
}

function Down(obj, id)
{
	_ajax.Post("/ws.aspx?Object=Music&Operation=IncrementDown&ID=" + id, null, null);
	obj.disabled = true;
}

function ReportMusicError(obj, id)
{
	_ajax.Post("/ws.aspx?Object=Music&Operation=IncrementError&ID=" + id, null, null);
	obj.disabled = true;
}

function ReportLyricError(obj, id)
{
	_ajax.Post("/ws.aspx?Object=Lyric&Operation=IncrementError&ID=" + id, null, null);
	obj.disabled = true;
}
</script>
</head>
<body>
<!-- TemplateBeginEditable name="广告位5" -->
<div class="Block2">
	<ilghar:Ad InnerID="13" />
</div>
<!-- TemplateEndEditable -->

<div class="Wrap">
    <div class="Block6">
        <div class="Block27">
            <div class="Left" id="Left">
                <h4 id="MusicName"><!--歌曲名称--></h4>
				<div id="Lyric">
					<!--歌词内容-->
				</div>
				<p id="Action1"><!--顶和踩--></p>
				<p id="Action2"><!--歌词错误和歌曲错误--></p>
            </div>
            <div class="Right" id="Right">
				<!-- TemplateBeginEditable name="广告位6" -->
				<ilghar:Ad InnerID="13" />
				<!-- TemplateEndEditable -->
				
				<!-- TemplateBeginEditable name="播放器" -->
				<div id="Player"></div>
				<!-- TemplateEndEditable -->
				
				<p><button onclick="PlayPrev()">上一首</button> <button onclick="PlayNext()">下一首</button></p>
				<div>
					节目地址：<input type="text" id="PageUrl" size="50" onclick="CopyToClipboard(document.getElementById('PageUrl').value);alert('网址已复制，粘贴给好友请按Crtl+V。')" />
					<script type="text/javascript">document.getElementById("PageUrl").value = window.location.href;</script>
				</div>
				<div id="List"><!--歌曲列表--></div>
            </div>
        </div>
    </div>
    <div class="Block15" id="Ad">
		<!-- TemplateBeginEditable name="广告位7" -->
		<h5>广告</h5>
		<div>
			<ilghar:Ad InnerID="17" />
		</div>
		<!-- TemplateEndEditable -->
    </div>
</div>
<!-- TemplateBeginEditable name="广告位8" -->
	<div class="Block2">
		<ilghar:Ad InnerID="13" />
	</div>
<!-- TemplateEndEditable -->

<ilghar:List Object="Music" Condition="BuildCondition()">
	<ilghar:Record>
		<script type="text/javascript">
			var music = new Object();
			music.ID = "<%=ID%>";
			music.InnerID = "<%=InnerID%>";
			music.Name = "<%=Name%>";
			music.PlayerID = "<%=PlayerID%>";
			music.URL = "<%=URL%>";
			music.Up = "<%=Up%>";
			music.Down = <%=Down%>;
			music.Star = null;
			music.Lyric = null;
		</script>
		<ilghar:List Object="Music.Star" Condition="IsDeleted=false and IsChecked=true and MusicID=ID">
			<ilghar:Record>
				<ilghar:List Object="Star" Page="1" PageSize="1" Condition="ID=StarID">
					<ilghar:Record>
						<script type="text/javascript">
							if (music.Star == null)
							{
								music.Star = "<a href=\"<%=BuildUrl("star_album.dwt", InnerID)%>\" target=\"_blank\" title=\"<%=Name%>\"><%=Name%></a>";
							}
							else
							{
								music.Star += " , <a href=\"<%=BuildUrl("star_album.dwt", InnerID)%>\" target=\"_blank\" title=\"<%=Name%>\"><%=Name%></a>";
							}
						</script>
					</ilghar:Record>
				</ilghar:List>
			</ilghar:Record>
		</ilghar:List>
		<ilghar:List Object="Lyric" Page="1" PageSize="1" Condition="IsDeleted=false and IsChecked=true and MusicID=ID">
			<ilghar:Record>
				<script type="text/javascript">
					music.Lyric = "<%=HttpUtility.UrlEncodeUnicode(Convert.ToString(Content))%>";
				</script>
			</ilghar:Record>
		</ilghar:List>
		<script type="text/javascript">
			_musics[_musics.length] = music;
		</script>
	</ilghar:Record>
</ilghar:List>

<ilghar:List Mark="System" Object="Player">
	<ilghar:Record>
		<script type="text/javascript">
			var player = new Object();
			player.ID = "<%=ID%>";
			player.Code = "<%=HttpUtility.UrlEncodeUnicode(Convert.ToString(Code))%>";
			_players[_players.length] = player;
		</script>
	</ilghar:Record>
</ilghar:List>

<script type="text/javascript">
var ids = "<%=Request.QueryString["ID"]%>".split("|");
for (var i = 0; i < ids.length; i++)
{
	for (var j = 0; j < _musics.length; j++)
	{
		if (_musics[j].InnerID == ids[i])
		{
			var temp = _musics[j];
			_musics[j] = _musics[i];
			_musics[i] = temp;	
			break;
		}
	}
}

var list = "<table cellpadding=\"5\" cellspacing=\"1\">";
for (var i = 0; i < _musics.length; i++)
{
	list += "<tr id=\"TR" + i + "\">";
	list += "<th><a href=\"javascript:Play(" + i + ")\">" + _musics[i].Name + "</a></th>";
	list += "<td>" + (_musics[i].Star == null ? "" : _musics[i].Star) + "</td>";
	list += "</tr>";
}
list += "</table>";
document.getElementById("List").innerHTML = list;

Play(0);

MakeColsEqual('Left', 'Right', 'Ad');
</script>
</body>
</html>
