var cookiestr;
var TotalSongs;

//插入歌曲列表入口函数
function Insertsong(songstr){
	 var tstr;
	 tstr = songstr.split("|");
	 if(tstr.length == 5){
		cookiestr = cookiestr + "#" + songstr;
		InitList();
	 }
}

//容错代码
function killerror() {return true;}
//window.onerror = killerror;

//初始化歌曲列表过程
function InitList(){
	 var songarray,htmlstr,i,j,tstr,ttstr,selectedindex;
	 htmlstr = "<select size=\"5\" name=\"SongList\" style=\"width:350px; background:#FEFDF8; color:#333333; border: 1px solid #333333;\" OnDblClick=\"play();\">";
	 songarray = cookiestr.split("#");
	 TotalSongs = 0;
	 for(i = 1;i < songarray.length;i++){
		tstr = songarray[i].split("|");
		if(tstr.length == 5){
			 TotalSongs += 1;
			 htmlstr += "<option value=\"" + songarray[i] + "\">";
			 ttstr = TotalSongs + "." + tstr[1] + "**" + tstr[3];
			 if(ttstr.length < 20){
				 ttstr = ttstr.replace("**"," - ");
			 }else{
				 ttstr = ttstr.replace("**"," - ");
				 ttstr = ttstr.substr(0,20) + "...";
			 }
			 htmlstr += ttstr + "</option>;";
		}
	 }
	 htmlstr += "</select>";
	 playlist.innerHTML = htmlstr;
}

//播放歌曲
function play(){
	 if(SongList.selectedIndex < 0) alert('请选择你要播放的曲目!');
	 else{
		var varvar,person,collect,song,url;
		varvar = SongList.options[SongList.selectedIndex].value.split("|");
		url = varvar[0];song = varvar[1];collect = varvar[2];person = varvar[3];SongID = varvar[4];
		if(person.length > 5) info_person.innerHTML = person.substr(0,5) + "...";
		else info_person.innerHTML = person;
		if(collect.length > 5) info_collect.innerHTML = collect.substr(0,5) + "...";
		else info_collect.innerHTML = collect;
		if(song.length > 5) info_song.innerHTML = song.substr(0,5) + "...";
		else info_song.innerHTML = song;
		MusicGeCi.innerHTML = " ";
		TEXTGeci.innerHTML = "<iframe name=\"LrcShow\" width=\"100%\" height=\"100%\" src=\"Player/LrcShow.Asp?id=" + SongID + "\">对不起，你的浏览器不支持框架。</iframe>";
		MusicTitle.innerHTML = song + "--" + collect;
		Exobud.URL = url;Exobud.controls.play();showTLab();
		return;
	 }
}

//控制按钮 上一首
function Last_OneOK(){
	 if((SongList.selectedIndex > 0) && (SongList.selectedIndex < TotalSongs)){
		SongList.options[SongList.selectedIndex - 1].selected = true;
		play();
	 }
}

//控制按钮 下一首
function Next_OneOK(){
	 if((SongList.selectedIndex >= 0) && (SongList.selectedIndex < TotalSongs - 1)){
		SongList.options[SongList.selectedIndex + 1].selected = true;
	 	play();
	 }
}

function showTLab(){
	 if(Exobud.playState == 1) Next_OneOK();
	 setTimeout("showTLab()",1000);
}