var PK_FN,PK_FName,PK_FType,PK_FHP,PK_FMP,PKTime;
var BallNum=0;
var PKNum=10;
function XH_PK() {
PK_MyKill=1;
	BallNum=BallNum+8;
	if (BallNum<400) {
		$("pk_ball").style.left=BallNum+"px";
		}else{
		if (PKNum!==1) {
			PKNum=PKNum-1;
			$("pk_text").innerHTML=PKNum;
			BallNum=0;
			XH_PK();
			}else{
			BallNum=0;
			PK_MyKill=0;
			PK_KillIng();
			}
		}
}

function PK_KillIng() {
$('XH_Player').style.top='130px';$('XH_Player').style.left='400px';
window.setTimeout("$('XH_Player').style.top='220px';$('XH_Player').style.left='250px';",500);

$(XH_MyTalkId).style.display='none';
var PK_KillHp=parseInt(Math.random()*7+1);
if ((BallNum>310)&&(BallNum<316)) {PK_KillHp=PK_KillHp+15;PlaySE(10)}
else if ((BallNum>255)&&(BallNum<366)) {PK_KillHp=PK_KillHp+5;PlaySE(11)}
else if ((BallNum>99)&&(BallNum<371)) {PlaySE(12)}
PK_KillHp=PK_KillHp+Math.floor(XH_Attack+XH_MyHp/20*XH_Grade)
if ((BallNum>370)||(BallNum<100)) {PK_KillHp=0;PlaySE(13)}
$("pk_text").innerHTML="";
clearInterval(PKTimer);
BallNum=0;
PKNum=10;
$("pk_ball").style.left="5px";
PK_MyKill=0;
$("pk_npc_text").innerHTML='<div id="pk_npc_textfont"><marquee direction=up style="text-align:center;height:120px;width:100px" align=middle behavior=slide scrollamount=30>-'+PK_KillHp+'</marquee></div>';
PK_FHP=PK_FHP-PK_KillHp;
//alert(PK_FHP);
NpcLife();
window.setTimeout("$('pk_text').innerHTML=PKNum;$('pk_npc_text').innerHTML='';PK_Kill_Npc()",1500);
}

function PK_Kill_Npc() {
if (PK_FHP<0) {
	$("XH_LoadJSNow").style.display='none';
	PlaySE(15);
	window.setTimeout("XH_LoadPK_Over()",3000);
	}else{
	PlaySE(14);
	var NpcKillHp=Math.floor(parseInt(Math.random()*8+1)*PK_FType+PK_FHP/20);
	$("pk_my_text").innerHTML='<div id="pk_my_textfont"><marquee direction=up style="text-align:center;height:120px;width:100px" align=middle behavior=slide scrollamount=30>-'+NpcKillHp+'</marquee></div>';
	$('pk_img').style.top='200px';$('pk_img').style.left='280px';
	window.setTimeout("$('pk_my_text').innerHTML=''",1200);
	window.setTimeout("$('pk_img').style.top='120px';$('pk_img').style.left='425px';",500);
	XH_MyHp=XH_MyHp-NpcKillHp;
	if (XH_MyHp<1) {
		XH_MyHp=0;
		$("XH_LoadJSNow").style.display='none';
		$("power_hp").style.width='1px';
		PlaySE(16);
		window.setTimeout("XH_LoadPK_Over()",3000)
		}else{
		$("power_hp").style.width=Math.floor(XH_MyHp/XH_MyAll*140);
		$("power_mp").style.width=Math.floor(XH_MyMp/XH_MyAll*140);
		PKTimer = window.setInterval("XH_PK()",40);
		}
	}
}

function NpcLife() {
if (PK_FHP>0) {$("power_npc_hp").style.width=Math.floor(PK_FHP/XH_MyAll*140)}else{$("power_npc_hp").style.width='0px'}
$("power_npc_mp").style.width=Math.floor(PK_FMP/XH_MyAll*140);
}

function XH_Load_PkXml() {
var PK_Freak_i=PK_Freak-1;
var XmlUrl="xml/Freak_"+XH_Grade+".Xml";
var XmlDoc=new ActiveXObject("Microsoft.XmlDOM");
XmlDoc.async = false;
XmlDoc.load(XmlUrl);
Nodes=XmlDoc.documentElement.childNodes;
var PkNum=XmlDoc.getElementsByTagName("item").length;
//alert(PkNum);
for(i=0;i<PkNum;i++) {
	if (i==PK_Freak_i) {
		PK_FN=Nodes.item(i).childNodes(0).text;
		PK_FName=Nodes.item(i).childNodes(1).text;
		PK_FType=Nodes.item(i).childNodes(2).text;
		PK_FHP=Nodes.item(i).childNodes(3).text;
		PK_FMP=Nodes.item(i).childNodes(4).text;
		//alert(PK_FN+" "+PK_FName+" "+PK_FType+" "+PK_FHP+" "+PK_FMP);
		$("power_npc_leave").innerHTML=PK_FType;
		PKTimer = window.setInterval("XH_PK()",40);
		NpcLife();
		}
	}
}

function PK_Ing() {
$("XH_LoadJSNow").innerHTML='<div id="pk_img"><img src="images/npc/Freak_'+PK_Freak+'.gif"></div><img id="pk_ball" src="images/pk_ball.gif"><div id="pk_text">10</div><div id="pk_npc_text"></div><div id="pk_my_text"></div>';
$("XH_LoadJSNow").style.display='block';
$("Power_npc_head").innerHTML='<img src="images/npc/Freak_'+PK_Freak+'_s.gif">';
$("Power_npc_bg").style.display='block';
OLtimer = window.setInterval("GameAjax('Online_PK.asp?i=0','XH_OnlineList',4)",4000);
MStimer = window.setInterval("GameAjax('ShowMess.asp?action=update&','XH_MsgList',1)",3000);
GameAjax('ShowMess.asp?action=send&c=FFF000&SN=场景互动&msg=网友[ '+XH_Name+' ]进入了PK状态&','XH_MsgList',1)
PlaySE(4);
$("XH_Loading").style.display='none';
var OBJ=document["Map_T"];
OBJ.GotoFrame(1);
XH_Load_PkXml()
}

PK_Ing();