<!--
function $(_sId){return document.getElementById(_sId)}
function SetComplete(){if(iscomp)return ;try{iscomp = true;ClearLastPosition();if($("IsAutoReverse").checked){setTimeout("GoPlayer(1);",3000);}}catch(e){document.title="SetComplete:" +e.toString();}}
function GoPlayer(num)
{
	if(num<0 || num>=PlayUrl.length || PlayUrl[num][0]=="" || PlayUrl[num][1]==""){/*alert("已经到本书结尾");*/return ;}
	top.window.location.href= PlayUrl[num][1];
}
var loaderInterval;
var tmpScroll;
var tmpScrollId;
var perLength;
var tmpMatchLrcLine=0;
var preMatchLrcLine=-1;
var count=0;
var tmpLrcContent="";
var tmpLrcs=new Array();
var lineCount=new Array();
var perLineCount=new Array();
var preLrcContent=new Array();
var nextLrcContent=new Array();

function lrcInterface(pID,lrcurl)
{
	var tmpOutput=$('LrcShower');
	count=0;
	tmpOutput.innerHTML="正在加载字幕信息，请您稍等片刻....";
	var tmp=setInterval(getObject,200);
	function getObject()
	{
		bdLRC=new bdSyncLRC();
		if(bdLRC!=null){
			clearInterval(tmp);
			bdLRC.setPlayer(pID);
			bdLRC.setURL(lrcurl);
			bdLRC.setOutput("LrcShower");
			bdLRC.Exchange();
			bdLRC.begin()
		};
		else{
			if(count==25){
				clearInterval(tmp);
				tmpOutput.innerHTML="可能是因为网络的原因，系统没有找到合适的字幕。请稍后重试";
				ShowLrcAd();
			};
			else
				count++;
			}
		}
	};
function bdSyncLRC(){
	var playerObj=null;
	var playerTypeStr=null;
	var lrcURL="";
	var lrcShower="";
	var lrcContent="";
	var lrcObjArray=new Array();
	this.preLRC=new Array();
	this.offsetTime=0;
	this.scrollMoveLen=20;
	if(arguments.length>=1)this.setPlayer(arguments[0]);
	if(arguments.length>=2)this.setURL(arguments[1]);
	if(arguments.length>=3)this.setOutput(arguments[2])};
	bdSyncLRC.prototype.setPlayer=function(){if(arguments.length>=1){arg=arguments[0];
	playerTypeStr=String(arg);
	if(typeof(arg)=="string")this.playerObj=$(arg);
	else if(typeof(arg)=="object")this.playerObj=arg}};
	bdSyncLRC.prototype.getPlayer=function(){if(typeof($("this.playerObj"))=='object')return this.playerObj;
	else return null};
	bdSyncLRC.prototype.setURL=function(){if(arguments.length>=1){this.lrcURL=arguments[0]}};
	bdSyncLRC.prototype.getURL=function(){return this.lrcURL};
	bdSyncLRC.prototype.setContent=function(){if(arguments.length>=1)this.lrcContent=arguments[0]};
	bdSyncLRC.prototype.getContent=function(){return this.lrcContent};
	bdSyncLRC.prototype.setLRC=function(){if(arguments.length>=1)this.lrcObjArray=arguments[0]};
	bdSyncLRC.prototype.getLRC=function(){return this.lrcObjArray};
	bdSyncLRC.prototype.setOutput=function(showerId){this.lrcShower=showerId};
	bdSyncLRC.prototype.getOutput=function(){
		if(this.lrcShower!=""){arg=this.lrcShower;
		if(typeof(arg)=="string")return $(arg);
		else if(typeof(arg)=="object")return arg};
		return null;
	};
	bdSyncLRC.prototype.multiLRC=function(lrcLine){
		thisObj=this;
		tmpVar=lrcLine.split("]");
		if(tmpVar.length>=2){
			lrcText=tmpVar[tmpVar.length-1];
			for(j=0;j<tmpVar.length-1;j++){
				lrcTime=tmpVar[j]+"]";
				thisObj.preLRC.push(lrcTime+""+lrcText);
			}
		}
	};
	bdSyncLRC.prototype.preSyncLRC=function(){
		if(this.getContent()==null||this.getContent()=="")return;
		lrcLines=this.getContent().split("\n");
		tmpArr=new Array();
		var tmpItem;
		for(i=0;i<lrcLines.length;i++)this.multiLRC(replaceStr(lrcLines[i]));
		this.preLRC.sort();
		var tmpVar="aaa";
		for(i=this.preLRC.length-1;i>=0;i--)
		{
			if(this.preLRC[i]==tmpVar){
				tmpVar=this.preLRC[i];
				this.preLRC.splice(i,1)
			};
			else
				tmpVar=this.preLRC[i];
		}
		preTime=0;
		indexLRC=1;
		tmpArr[0]=new LRCItem(0,"");
		for(i=0;i<this.preLRC.length;i++)
		{
			if(this.preLRC[i].length>9)
			{
				tmpTime=getLyrcTime(this.preLRC[i]);
				tmpLrc=getLyrc(this.preLRC[i]);
				if(tmpTime<preTime||tmpLrc=="")continue;
				if(tmpTime==0){tmpArr[0].lrcContent=tmpLrc;continue};
				preTime=tmpTime;
				tmpItem=new LRCItem(tmpTime,tmpLrc);
				tmpArr[indexLRC++]=tmpItem;
			}
		};
		var tmpItem=new LRCItem(3600,"Over...");
		tmpArr[indexLRC]=tmpItem;
		this.setLRC(tmpArr);
		tmpLrcs=this.getLRC();
		tmpScroll=this.getOutput();
		tmpScrollId=this.getOutput();
		perLength=this.scrollMoveLen;
	};
	function replaceStr(tmpStr){return tmpStr.replace(/^\s*|\s*$/g,"")};
	function getLyrc(tmpStr){try{tmpArray=tmpStr.split("]");return tmpArray[tmpArray.length-1]}catch(e){};return ""};
	function getLyrcTime(tmpStr){
		try
		{
			tmpChar=tmpStr.split("]")[0].split("[")[1];
			tmpVar=tmpChar.split(":");
			if(tmpVar.length<2)return 0;
			min=tmpVar[1].split(".")[0];
			tmpInt=parseInt(tmpVar[0])*60+parseFloat(min);
			if(!isNaN(tmpInt))return tmpInt;
		}
		catch(e){};
		return 0;
	};
	function LRCItem(){
		var lrcTime=-1;
		var lrcContent="";
		if(arguments.length>=2)
		{
			this.lrcTime=arguments[0];
			this.lrcContent=arguments[1];
		}
	};

	bdSyncLRC.prototype.Exchange=function(){
		var xmlhttp=null;
		if(window.XMLHttpRequest){xmlhttp=new XMLHttpRequest()};
		else
		{
			if(window.ActiveXObject)
			{
				try
				{
					xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
				}
				catch(ee){xmlhttp=new ActiveXObject("MSXML.XMLHTTP")}
			}
		};
		var tmpURL=this.getURL();
		thisObj=this;
		//var tmpStr="";
		
		try
		{
			xmlhttp.open("GET",tmpURL,false);
			xmlhttp.onreadystatechange=function()
			{
				if((xmlhttp.readyState==4)&&(xmlhttp.status==200))
				{
					thisObj.setContent(bdBytes2Str(xmlhttp.responseBody));
				}
			};
			xmlhttp.send(null);
		}
		catch(ee){}
	};

	bdSyncLRC.prototype.begin=function(){thisObj=this;
	tmpPlayerObj=thisObj.getPlayer();
	var tmpOutput=$('LrcShower');
	var tmpI=setInterval(getlrc,100);
	count=0;
	function getlrc(){
		if(typeof(thisObj.getContent())!="undefined")
		{
			clearInterval(tmpI);
			thisObj.preSyncLRC();
			getPlayingTime(thisObj.getPlayer(),thisObj);
		};
		else
		{
			if(count==50)
			{
				clearInterval(tmpI);
				tmpOutput.innerHTML="无字幕"
				ShowLrcAd();
			};
			else count++;
		}
	}
};
function getPlayingTime(playerObj,bdLRCObj){
try{
tmpbdLRCObj=bdLRCObj;
var tmpPlayerObj=playerObj;
if(typeof(tmpPlayerObj)=="string")tmpPlayerObj=$(tmpPlayerObj);
window.setTimeout("getPlayingTime(tmpPlayerObj,tmpbdLRCObj)",1000);
bdsyncLyrc(tmpbdLRCObj)
}catch(e){document.title="getPlayingTime..."+e.toString()}
};
function getCurrentPosition(tmpPlayer){if(playerTypeStr=="ObjWmp")return tmpPlayer.CurrentPosition;
else return tmpPlayer.GetPosition()/1000};
function findLoc(bdLRCObj){var start;
var end;
var tmpPlayer=bdLRCObj.getPlayer();
currentTime=getCurrentPosition(tmpPlayer);
if(currentTime<0) currentTime=0;
if(currentTime>=tmpLrcs[tmpMatchLrcLine].lrcTime){start=tmpMatchLrcLine;
end=tmpLrcs.length};
else{start=0;
end=tmpMatchLrcLine+1};
for(j=start;j<end;j++){nowLrc=tmpLrcs[j];
nextLrc=tmpLrcs[(j<end-1)?j+1:j];
nowTime=nowLrc.lrcTime+bdLRCObj.offsetTime;
nextTime=nextLrc.lrcTime+bdLRCObj.offsetTime;
if(nowTime<=currentTime&&currentTime<nextTime)return j}};

function bdsyncLyrc(bdLRCObj){
	try{
		j=findLoc(bdLRCObj);
		tmpMatchLrcLine=j;
		tmpLrcContent=replaceStr(tmpLrcs[j].lrcContent);
		if(preMatchLrcLine!=tmpMatchLrcLine){
			tmpScroll.innerHTML=tmpLrcContent;
			findSetText(tmpLrcContent);
		};
		preMatchLrcLine=tmpMatchLrcLine;
	}catch(e){document.title="bdsyncLyrc="+e.toString()}
};
function showCurrentPosition(){RecordCurrentPosition()}

var tmpPlayerText="";
var tmpPlayerTextCur=0;
function findSetText(text)
{
	var cur=0;
	try{
		if(tmpPlayerText=="") /* init */{tmpPlayerText = $("PlayerText").innerHTML;};
		cur = tmpPlayerText.indexOf(text,tmpPlayerTextCur);
		if(cur==-1)
			cur = tmpPlayerText.indexOf(text);
		if(cur==-1 || cur==tmpPlayerTextCur)return ;
		$("PlayerText").innerHTML = tmpPlayerText.substring(0,cur) + "<u id=\"ctl\">" + text +"</u>" + tmpPlayerText.substr(cur+text.length);
		tmpPlayerTextCur = cur;
		SetTextScrollTopLine();
	}catch(e){document.title="findSetText:" +e.toString();}
}

function SetTextScrollTopLine()
{
	try{
	if(!$("chkIsAutoScroll").checked)return ;
	var textH = 235,setOffet = 60;
//	var curScrTop = $("PlayerText").scrollTop,textScrTop = $("ctl").offsetTop;
//	var starScrTop = Math.floor(textScrTop/textH)*textH,endScrTop = starScrTop+textH;
//	document.title= "p:" + Math.floor(textScrTop/textH) + " c:" +curScrTop + " s:" + starScrTop + " " + endScrTop + " t:" + textScrTop ;
//	if(curScrTop<(starScrTop) || curScrTop>(endScrTop-setOffet) || textScrTop<starScrTop || textScrTop>(endScrTop-setOffet))
	$("PlayerText").scrollTop = $("ctl").offsetTop - setOffet;
	}catch(e){document.title="SetTextScrollTopLine:" +e.toString();}
}

function SaveCurrentPosition()
{
	try{
	if(Wmp.CurrentPosition<1 || Wmp.CurrentPosition>=Wmp.duration){return ;}
	BookXMLStore.load("BookXMLStore");BookXMLStore.setAttribute("SavePositionBookID",BookID);BookXMLStore.setAttribute("SavePositionBookVolumeNum",BookVolumeNum);BookXMLStore.setAttribute("SavePosition",Wmp.CurrentPosition);BookXMLStore.save("BookXMLStore");
	}catch(e){document.title="ClearCurrentPosition:" +e.toString();}
}

function ClearCurrentPosition()
{
	try{
	BookXMLStore.load("BookXMLStore");BookXMLStore.setAttribute("SavePositionBookID",0);BookXMLStore.setAttribute("SavePositionBookVolumeNum",0);BookXMLStore.setAttribute("SavePosition",0);BookXMLStore.save("BookXMLStore");
	}catch(e){document.title="ClearCurrentPosition:" +e.toString();}
}

function LoadPosition()
{
	try{
	var Position=0;
	BookXMLStore.load("BookXMLStore");
	if(BookXMLStore.getAttribute("SavePositionBookID")==BookID && BookXMLStore.getAttribute("SavePositionBookVolumeNum")==BookVolumeNum && parseInt(BookXMLStore.getAttribute("SavePosition"))>0)
	{
		Position = parseInt(BookXMLStore.getAttribute("SavePosition"));
	}
	else if(BookXMLStore.getAttribute("LastBookID")==BookID && BookXMLStore.getAttribute("LastBookVolumeNum")==BookVolumeNum && parseInt(BookXMLStore.getAttribute("LastBookPosition"))>0)
	{
		Position = parseInt(BookXMLStore.getAttribute("LastBookPosition"));
	}
	
	if(isNaN(Position) || Position<1)
		return ;
	
	if(Position>10)Position = Position-5;
	Wmp.CurrentPosition = Position;
	}catch(e){document.title="LoadPosition:" +e.toString();}
}
function ClearLastPosition()
{
	try{
	writeCookie("LB","",1);
	BookXMLStore.load("BookXMLStore");BookXMLStore.setAttribute("LastBookID",0);BookXMLStore.setAttribute("LastBookVolumeNum",0);BookXMLStore.setAttribute("LastBookPosition",0);BookXMLStore.setAttribute("LastBookName","");BookXMLStore.setAttribute("LastBookVolumeName","");BookXMLStore.setAttribute("LastBookUrl","");BookXMLStore.save("BookXMLStore");
	}catch(e){document.title="ClearLastPosition:" +e.toString();}
}

var playerVolume = 0;
function RecordCurrentPosition()
{
	try{
	if(Wmp.CurrentPosition<1){return ;}
	if(playerVolume!=Wmp.volume)
	{
		playerVolume = Wmp.volume;
		BookXMLStore.load("BookXMLStore");
		BookXMLStore.setAttribute("PlayerVolume",Wmp.volume);
		BookXMLStore.save("BookXMLStore");
	}
	if(Wmp.CurrentPosition>=Wmp.duration){ClearLastPosition();}
	else{
		writeCookie("LB",encodeURIComponent(BookID + ";"+ BookVolumeNum +";" + Wmp.CurrentPosition + ";"+ BookName +";" + BookVolumeName + ";" + BookVolumeUrl +";"),24*60);
		//BookXMLStore.load("BookXMLStore");BookXMLStore.setAttribute("LastBookID",BookID);BookXMLStore.setAttribute("LastBookVolumeNum",BookVolumeNum);BookXMLStore.setAttribute("LastBookPosition",Wmp.CurrentPosition);BookXMLStore.setAttribute("LastBookName",BookName);BookXMLStore.setAttribute("LastBookVolumeName",BookVolumeName);BookXMLStore.setAttribute("LastBookUrl",BookVolumeUrl);BookXMLStore.save("BookXMLStore");
	}
	if(Wmp.CurrentPosition>=(Wmp.duration-1)){SetComplete();}
	}catch(e){document.title="RecordCurrentPosition:" +e.toString();}
}
function SetAutoReverse(){BookXMLStore.load("BookXMLStore");BookXMLStore.setAttribute("IsAutoReverse",$("IsAutoReverse").checked);BookXMLStore.save("BookXMLStore");}

function AutoPlay()
{
	
	//LoadPosition();
	//Wmp.Play();
	try{
	BookXMLStore.load("BookXMLStore");
	}catch(e){alert("载入数据失败~\r\n\r\n请尝试删除：C:\\Documents and Settings\\***\\UserData 下所有文件\r\n(\"***\"是您电脑的登陆名)");}
	try{
	$("IsAutoReverse").checked = (BookXMLStore.getAttribute("IsAutoReverse")==null|| BookXMLStore.getAttribute("IsAutoReverse")=="true");LoadLrc();setInterval(showCurrentPosition,500);
	ClearLastPosition();
	if(BookXMLStore.getAttribute("PlayerVolume")!=null && !isNaN(BookXMLStore.getAttribute("PlayerVolume")))
	{
		setTimeout("Wmp.volume="+ BookXMLStore.getAttribute("PlayerVolume") +";",1000);
	}
	setInterval(RecordCurrentPosition,500);
	}catch(e){document.title="AutoPlay:" +e.toString();}

	hookLinks();
}

function hookkey(e)
{
	try{
		var key=event.keyCode;
		if(key!=32)return ;
		var state = Wmp.playState;
		if (state == 0)
			Wmp.Play();
		else if (state == 1)
			Wmp.Play();
		else if (state == 2)
			Wmp.Pause();
	}catch(e){document.title="hookkey:" +e.toString();}
}
document.onkeydown = hookkey;

var LrcAdText = new Array(),LrcAdi;
LrcAdText[LrcAdText.length] = "听书网拥有多组服务器，能够为中国网通、中国电信等宽带用户提供流畅视听效果。";
LrcAdText[LrcAdText.length] = "如果您对听书网有任何意见或建议，请通过页面下方的帮助与我们联系。";
LrcAdText[LrcAdText.length] = "您可以将有声图书下载到MP3、MP4、手机上。";
LrcAdText[LrcAdText.length] = "休息时、上班途中、旅途中，既休闲又健康。";
LrcAdText[LrcAdText.length] = "通过银行卡、神州行充值卡(无需手机)为<a href=\"../desc/pay.shtml\" target=\"_blank\">听书网账户充值</a>。";
LrcAdText[LrcAdText.length] = "您可以免费下载同步字幕文件到MP3、MP4、手机上。";
LrcAdText[LrcAdText.length] = "听书网新版功能测试期间，服务可能不稳定。请您见谅!";
LrcAdText[LrcAdText.length] = "免费注册会员后能收听更多免费图书";
LrcAdText[LrcAdText.length] = "选中右侧“自动播放下一篇”功能将按顺序连续播放图书章节。";
LrcAdText[LrcAdText.length] = "你可以用鼠标拖动控制条上的 <img src=\"../images/help/volume.jpg\" border=0 width=49 height=19> 调节音量。";
LrcAdText[LrcAdText.length] = "在当前窗口中按空格键可以在暂停和播放间快速切换";
LrcAdText[LrcAdText.length] = "文字中用下划线标识的文字，是当前阅读的内容。";
LrcAdText[LrcAdText.length] = "dict!英语栏目收听时可用鼠标<b>双击单词查看英汉词典</b>解释";
LrcAdText[LrcAdText.length] = "要是您觉得本书不错，请点击左侧“投一票”，为作者加油";
LrcAdText[LrcAdText.length] = "new cool! 现在您可以<a href=\"../task/\" target=\"_blank\">上传原创有声作品</a>了";
LrcAdText[LrcAdText.length] = "从此不读书，天方听书网";
LrcAdi = Math.floor((LrcAdText.length*Math.random()));
function ShowLrcAd()
{
	try{
	var lrcs = $('LrcShower');
	if(LrcAdi>=LrcAdText.length)LrcAdi=0;lrcs.innerHTML =LrcAdText[LrcAdi];setTimeout("ShowLrcAd()",500*(HTML2TEXT(LrcAdText[LrcAdi]).length));
	LrcAdi++;}catch(e){document.title="ShowLrcAd="+e.toString();}
}

function LoadLrc()
{
	var pID="ObjWmp";if(BookVolumeIsLrc!=""){$('LrcShower').style.display="";if(typeof(lrcInterface)=="function"){lrcInterface(pID,"http://www.tingbook.com/lrcs/"+ BookID +"/" + encodeURIComponent(BookFileName) + ".lrc");}else{ShowLrcAd();}}else ShowLrcAd();
}

function hookLinks(){var Links = document.body.getElementsByTagName("a");for(var i=0;i<Links.length;i++){var l = Links[i];l.onclick = function(){try{if(Wmp.playState!=2)return true;}catch(e){;};if(this.target.toLowerCase()=="_blank" || this.target.toLowerCase()=="_top"){return true;};return confirm("离开当前页面，播放将会停止。您确定么？\r\n继续播放请点击“取消”。");	};}}
function FormatTimer(mill){var Minutes,Seconds;Minutes = 0;Seconds = 0;mill = parseInt(mill);if(mill>=60){Minutes = Math.floor(mill/60) ;mill = mill%60;};Seconds = Math.floor(mill);if(Seconds<1)Seconds = 0;if (Minutes<10)Minutes= "0" + Minutes;if (Seconds<10)Seconds= "0" + Seconds;	return Minutes + ":"+ Seconds;}
function HTML2TEXT(s){return s.replace(/<script.+?\/script>/gi, "").replace(/<.+?>/g, "");}


//-->