//定义移动对象和移动坐标
var Mouse_Obj=null,_xx,_yy;
document.onmousemove=function() {
if(Mouse_Obj) {
Mouse_Obj.style.top=_yy+event.y;
Mouse_Obj.style.left=_xx+event.x;
	//event.returnValue=false;
	}
}
//停止拖动
document.onmouseup=function() {Mouse_Obj=null}
function m(o) {
if((event.srcElement.className == "GW_C_2")||(event.srcElement.className == "swf")) {return};
Mouse_Obj=$(o);
_xx=parseInt(Mouse_Obj.style.left)-event.x;
_yy=parseInt(Mouse_Obj.style.top)-event.y;
}

//对所有层操作
function CloseAll(ThisWin) {
var WinDiv = $(ThisWin);
var objs = document.getElementsByTagName("div");   
var i;
for(i = 0;i < objs.length;i++) {objs[i].style.zIndex = 20;}
WinDiv.style.zIndex = 21;
}

//WIN开始
function GameWin(WinId,WinT,WinUrl,Width,Height,Tops,Lefts,Types) {
var WinContent;
PlaySE(2);
var WinDiv = $(WinId);
	if (WinDiv) {
	CloseAll(WinId);
	WinDiv.style.display='block';
	WinDiv.style.zIndex='20';
	}else{
	var oDiv = document.createElement("DIV");
	oDiv.id = WinId;
	oDiv.style.width = Width+16;
	oDiv.style.height = Height+36;
	oDiv.style.top = Tops;
	oDiv.style.left = Lefts;
	//oDiv.style.visibility = 'visible';
	oDiv.style.position = 'absolute';
	oDiv.style.zIndex = 21;
	oDiv.onmousedown = function(){window.CloseAll(this.id);m(WinId)};
	oDiv.ondblclick = function(){alert(this.style.left+" "+this.style.top)};
	if ((Types==1)||(Types==4)) {WinContent="<iframe width=100% height=100% frameborder=0 scrolling=auto src="+WinUrl+"></iframe>"}
	if (Types==2) {WinContent="<div style='padding:5px'>"+WinUrl+"</div>"}
	if (Types==3) {WinContent=""}
	if (Types==4) {
	oDiv.innerHTML="<TABLE class='GW_table' cellSpacing=0 cellPadding=0><tr><td colspan='3' class='GW_T'><span class='GW_T_1' style='width:"+(Width-25)+"'>"+WinT+"</span><span class='GW_T_2'><img class='GW_but1_out' src='images/blank.gif' onmouseover=\"PlaySE(1);this.className='GW_but1_on'\" onmouseout=\"this.className='GW_but1_out'\" onmousedown=\"this.className='GW_but1_down'\" onmouseup=\"DelDiv('"+WinId+"')\" alt='关闭窗口'></span></td><tr><td class='GW_C_1'></td><td class='GW_C_2' style='width:"+Width+"px;height:"+Height+"px' valign=top id='Desc_"+WinId+"'>"+WinContent+"</td><td class='GW_C_3'></td></tr><tr><td class='GW_F_1'></td><td class='GW_F_2'></td><td class='GW_F_3'></td></tr></table>"
	}else if(Types==5){
	oDiv.innerHTML="<div style='width:470px;height:455px;padding:5px;border:1px #000000 solid;background:#9ECDD6'><div style='height:16px;overflow:hidden;margin-bottom:2px'><div style='float:left;font-weight:bold;width:100px;color:#1093E6'>即时交谈</div><div style='float:right;font-weight:bold;width:15px;overflow:hidden;cursor:hand;color:#1093E6' onclick=DelDiv('"+WinId+"')>×</div></div><iframe width=460 height=427 frameborder=0 scrolling=auto src="+WinUrl+"></iframe></div>";
	}else{
	oDiv.innerHTML="<TABLE class='GW_table' cellSpacing=0 cellPadding=0><tr><td colspan='3' class='GW_T'><span class='GW_T_1' style='width:"+(Width-25)+"'>"+WinT+"</span><span class='GW_T_2'><img class='GW_but1_out' src='images/blank.gif' onmouseover=\"PlaySE(1);this.className='GW_but1_on'\" onmouseout=\"this.className='GW_but1_out'\" onmousedown=\"this.className='GW_but1_down'\" onmouseup=\"DelDiv('"+WinId+"')\" alt='关闭窗口'></span></td><tr><td class='GW_C_1'></td><td class='GW_C_2' style='width:"+Width+"px;height:"+Height+"px' valign=top id='Desc_"+WinId+"'>"+WinContent+"</td><td class='GW_C_3'></td></tr><tr><td class='GW_F_1'></td><td class='GW_F_2'></td><td class='GW_F_3'></td></tr></table>"
	}
	document.body.appendChild(oDiv);
	if (Types==3) {GameAjax(WinUrl,'Desc_'+WinId,3)}
	}
}
//删除DIV
function DelDiv(ThisWin,Types) {
if (Types!==1) PlaySE(2);
if (Types==2) {
var ObjWin='Desc_'+ThisWin;
$(ObjWin).innerHTML='';
	}
$(ThisWin).parentNode.removeChild($(ThisWin))
}
//音效
function PlaySE(ID) {
var OBJ = document["SE"]
try{OBJ.GotoFrame(0);OBJ.GotoFrame(ID)}
catch(err){}
}

//按钮效果
function HotButton(ButtonCM,ButtonID,ButtonSE) {
if (ButtonSE!==0) {PlaySE(ButtonSE)}
$(ButtonID).scrollTop=ButtonCM;
}
//聊天色彩更换
function ChangeMsgColor(Color) {
if (XH_MsgContent.value=="") {XH_MsgContent.value="温馨提示：可在此输入信息后再调色"}
XH_MsgContent.style.color=Color;
XH_MsgColor.value=Color;
PlaySE(9);
//DelDiv("myface");
}
//表情
function ChangeFace(Num) {
XH_MsgContent.value="/face:"+Num;
SendMsgNow();
DelDiv("myface");
}

//角色方向
function PlayerFX(_L,_T) {
var Obj=XH_Player;
Obj.scrollLeft=_L;
Obj.scrollTop=_T;
}

var Snum,Send;
var Sfx=1;
var Wtop=0;
var Wleft=0;
//sfx:1,2,3,4 上下左右
//n1滚屏长度 n2方向 n3房间 n4场景
//n1横坐标 n2纵坐 n3房间 n4场景

function $S(n1,n2,n3,n4) {
XH_WayList="";
AjaxClear();
$("XH_LoadJSNow").style.display='block';
ClearAllUser();
if (n4==XH_OnMap) {
	XH_Room=n3;
	Snum=0;
	Send=n1;
	Sfx=n2;
	var MapJs='GameMap/scene'+XH_OnMap+'_'+XH_Room+'.js?t='+getDataTimes();
	LoadMap.src=MapJs;
	if (Sfx==1){actor.nowPoint.y=Send+18}else if(Sfx==2){actor.nowPoint.y=468-Send}else if(Sfx==3){actor.nowPoint.x=Send+18}else if(Sfx==4){actor.nowPoint.x=768-Send}
	}else{
//新场景
	PlaySE(5);
	$('XH_Myname').style.display='none';
	XH_OnMap=n4;
	XH_Room=n3;
	XH_Left=n1;
	XH_Top=n2;
	window.setTimeout("GetMapHtml()",850);
	}
}

function Scrolling() {
//alert(Snum+" "+Send);
if (Snum<Send) {
	if (Snum<Send-30) {Snum=Snum+30}else if (Snum<Send-20) {Snum=Snum+20}else{Snum=Snum+1}
	if(Sfx==1) {
	$("XH_MapF").scrollTop=$("XH_MapT").scrollTop=Wtop-Snum;
	$("XH_Player").style.top=XH_Top+Snum;
	$("XH_Myname").style.top=XH_Top+Snum-10;
		}
	else if(Sfx==2) {
	$("XH_MapF").scrollTop=$("XH_MapT").scrollTop=Wtop+Snum;
	$("XH_Player").style.top=XH_Top-Snum;
	$("XH_Myname").style.top=XH_Top-Snum-16;
		}

	else if(Sfx==3) {
	$("XH_MapF").scrollLeft=$("XH_MapT").scrollLeft=Wleft-Snum;
	$("XH_Player").style.left=XH_Left+Snum;
	$("XH_Myname").style.left=XH_Left+Snum-12;
		}
	else if(Sfx==4) {
	$("XH_MapF").scrollLeft=$("XH_MapT").scrollLeft=Wleft+Snum;
	$("XH_Player").style.left=XH_Left-Snum;
	$("XH_Myname").style.left=XH_Left-Snum-12;
		}
	ScrollTime=window.setTimeout("Scrolling()",10);
	}else{
	Wtop=$("XH_MapF").scrollTop;
	Wleft=$("XH_MapF").scrollLeft;
	XH_Left=$("XH_Player").offsetLeft;
	XH_Top=$("XH_Player").offsetTop;
	$(XH_MyTalkId).style.left=XH_Left-95;
	$(XH_MyTalkId).style.top=XH_Top-35;
	}
}
function LoginScroll() {
//alert(LoadStarY+" "+LoadStarX);
$('XH_MapF').scrollLeft=$('XH_MapT').scrollLeft=$('XH_MapF').scrollLeft+LoadStarX;
$('XH_MapF').scrollTop=$('XH_MapT').scrollTop=$('XH_MapF').scrollTop+LoadStarY;
Wtop=LoadStarY;
Wleft=LoadStarX;
}
//判断str1是否存在str2
function IsInclude(str1,str2){
var s = str1.indexOf(str2);
if(s==-1){return false;}else{return true;}
}
//音乐播放
var MusicN=parseInt(Math.random()*19+1);
var OnMusic,MusicTimer,MusicAllNum;
var OnMusicNum=0; //当前曲目
var MusicXml=1;		//当前列表
function PlayMusic(Num) {
OnMusicNum=Num;
PlaySE(2);
clearInterval(MusicTimer);
var XmlUrl="xml/MusicList.asp?List="+MusicXml;
var XmlDoc=new ActiveXObject("Microsoft.XmlDOM");
XmlDoc.async = false;
XmlDoc.load(XmlUrl);
Nodes=XmlDoc.documentElement.childNodes;
var MPlayNum=XmlDoc.getElementsByTagName("item").length;
MusicAllNum=MPlayNum;
for(i=0;i<MPlayNum;i++) {
	if (i==Num) {
		OnMusic=Nodes.item(i).childNodes(0).text+"-"+Nodes.item(i).childNodes(1).text;
		InfoMusicUrl(Nodes.item(i).childNodes(2).text);
		}
	}
}

function InfoMusicUrl(MusicUrl) {
document.Music_BGM.url=MusicUrl;
Music_BGM.controls.play();
$("XH_MainMenu_R_1").innerHTML="<marquee id='Music_BGM_Text' scrollamount=2 behavior=alternate>正在缓冲...&nbsp;</marquee>";
$("Music_bg").style.display='none';
PlayMusicIng();
popmsg("温馨提示","当前播放歌曲 <font color=#ff00ff>"+OnMusic+"</font>",220,60);
MusicTimer = window.setInterval("PlayMusicIng()",1000);
}

function PlayMusicIng() {
var MTypes=document.Music_BGM.playState;
if(MTypes==6) {$("Music_BGM_Text").innerHTML='正在缓冲...'}
if(MTypes==3) {$("Music_BGM_Text").innerHTML="&nbsp;&nbsp;"+OnMusic+'　'+document.Music_BGM.controls.currentPositionString+'｜'+ document.Music_BGM.currentMedia.durationString+"&nbsp;&nbsp;"}
if(MTypes==10) {CatMusic(1)}
if((MTypes==1)||(MTypes==2)||(MTypes==8)) {
	clearInterval(MusicTimer);
	$("XH_MainMenu_R_1").innerHTML="<marquee id='Music_BGM_Text' scrollamount=2 behavior=alternate>跳转下一曲...&nbsp;</marquee>";
	window.setTimeout("PlayMusic_But(2)",1000)
	}
}

function PlayMusic_But(Types) {
var NextNum;
if (Types==1) {
	if (OnMusicNum > 0) {var NextNum=OnMusicNum-1}else{var NextNum=MusicAllNum-1}
	}
if (Types==2) {
	if (OnMusicNum < MusicAllNum-1) {var NextNum=OnMusicNum+1}else{var NextNum=0}
	}
PlayMusic(NextNum);
}

function CatMusic(Types) {
PlaySE(2);
if(Types==2) {$("Music_List").innerHTML="音乐编辑功能开发中"}
else if(Types==3) {GameAjax('integrate/MusicAdd.Html?i=1&','Music_List',3)}
else if (Types==1) {
	clearInterval(MusicTimer);
	Music_BGM.controls.stop();
	$('XH_MainMenu_R_1').innerHTML='已停止&nbsp;';
	$('Music_bg').style.display='none';
	}
}

//pop窗口
var PopW=220;	//窗口宽
var PopH=60;	//窗口高,建议个位数为0
var PopT=20;	//越小越快
var PopO=1500;	//越大显示越久
var popR=2;	//距离右边
var popF=2;	//距离底部
//以下不用修改
var popTop=0;
var PopTimer;
popF=popF+34;
var oPopup = window.createPopup();
function popmsg(msgtitle,msgstr,_W,_H){
popTop=10;
clearTimeout(PopTimer);
PopW=_W;
PopH=_H;
var Popwin="<div style=\"border:1px #3B82BD solid;width:"+PopW+"px;height:"+(PopH-0)+"px;padding:3px\">";
Popwin+="<div style=\"height:100%;border:1px #6D93C8 solid;background:#E1ECF6;color:#205681;padding:2px;font-size:12px;line-height:18px;overflow:auto\"><b><font color=#04387E>"+msgtitle+"：</font></b><br>"+msgstr+"</div></div>";
oPopup.document.body.innerHTML = Popwin;
PopOpen();
}

function PopOpen(){
window.status=popTop;
if(popTop>PopO){
clearTimeout(PopTimer);
oPopup.hide();
return;
}else if(popTop<PopH+10){
oPopup.show(screen.width-(PopW+popR),screen.height-(PopH+popF),PopW,popTop);
}
else if(popTop>PopH){
oPopup.show(screen.width-(PopW+popR),screen.height-(PopH+popF),PopW,PopH);
}
popTop+=10;
PopTimer=setTimeout("PopOpen()",PopT);
}

var MovieIng=0;		//0为未播放
//是否正在播放电影
function PlayFlv(FlvW,FlvH,FlvL,FlvT,FlvUrl,Type) {
MovieIng=1;
$("XH_Film").style.display='block';
$("XH_Film").style.left=FlvL;
$("XH_Film").style.top=FlvT;
$("XH_Film").style.width=FlvW;
$("XH_Film").style.height=FlvH;
if (Type=="New") {$("XH_Film").src="flvplay.htm?"+FlvUrl}
}

function CloseFlv() {
MovieIng=0;
$("XH_Film").style.display='none';
$("XH_Film").src="about:blank";
$("XH_Film").style.width="0px";
}

function BigPlayFlv() {
if (($("XH_Film").style.width=="118px")&&(MovieIng==1)) {
PlayFlv(450,340,330,0);
}else if (($("XH_Film").style.width=="450px")&&(MovieIng==1)) {
	PlayFlv(118,86,392,55);
	}
}

function OPlayFlv() {PlayFlv(118,86,392,55,'NoUrl','New')}