var IsLive=false;
var Record="";
var IsPass;
var PassHash;
var iRoom = new Object();
$(function(){
if(iRoomID)
{
//get static Roominfo
	if(typeof(DRoomJS)!="undefined")
	{
		var DRoomJSObj = eval("("+DRoomJS+")");
		$.each(DRoomJSObj.data,function(i,e){
			//iRoom.maxnum=e.maxnum;
			iRoom=e;
			if(e.face!=""){$("#avatar_image")[0].src=e.face;}
			document.title=unescape(unescape(e.unick))+" "+document.title;
			$("#iUname").text(unescape(unescape(e.unick)));
			$("#GiftReceiveUser")[0].value=unescape(unescape(e.unick));
			$("#iRoomid").text("（"+iRoomID+"）");
			$("#liveTitle").text(e.UserLabel);
			$("#RoomUserID")[0].value=e.uid;
			iInfo.Partner=e.uid;
			$("#GiftReceiveUser").attr("uid",e.uid);
			$("#GiftReceiveUser").attr("roomid",iRoomID);
			if(e.pubnotice!=""){$("#PubNotice").html("<a href='"+e.pubnoticehref+"#' target=_blank>"+unescape(e.pubnotice)+"</a>");}
			var iStrPriNotice = '<li class="undefined"><span class="t">{1} </span><img src="/images/pixel.gif" style="display:none" class="uIco {2}"><a id="{3}" class="u" href="javascript://" onclick="LinkLayerClick(this)">{4} </a> 对你说：<a href="{6}" target=_blank>{5}</a></li>';
			if(e.prinotice!=""){$("#PriChatList").append($.format(iStrPriNotice,'',GetSendTime,'',e.uid,unescape(unescape(e.unick)),unescape(e.prinotice),e.prinoticehref))}
			if(e.background!=""){$("body").css("background-image","url("+e.background+")");}
			$("body").css("background-attachment",e.backgroundfix);
			if($.browser.msie){
			$("#iBody").css("margin-top",e.styletop);
			}
			else
			{
			$("#iBody").css("margin-top",e.styletop+"px");
			}
			//////////
			if(iRoomID==iInfo.RoomID)
			{
				$("#skin_box").css("display","block");
				SetImg(e.background);
				try{
					$("input[@type=radio][name=StyleTop][value="+e.styletop+"]").attr("checked","true");
					$("#BackgroundFix")[0].selectedIndex=e.backgroundfix=="fixed"?0:1;
					$("#tPubNotice").text(unescape(e.pubnotice));
					$("#tPriNotice").text(unescape(e.prinotice));
					$("#tPubNoticeHref").attr("value",e.pubnoticehref);
					$("#tPriNoticeHref").attr("value",e.prinoticehref);
				}
				catch(err){}
			}
			else
			{
				if(e.pass)
				{
					if(e.pass!='')
					{
						PassHash=e.pass;
						IsPass=window.setInterval('ShowPassConfirm()',1*1000);
					}
				}
			}
			//////////
		});
		getroominfo();
	}
	else
	{
		$.get("/f/CreatRoomInfo.asp",{ac:'GetRoomInfo',rid:iRoomID,t:GetSendTime()},function(){
			var DRoomJSObj = eval("("+DRoomJS+")");
			$.each(DRoomJSObj.data,function(i,e){
				//iRoom.maxnum=e.maxnum;
				iRoom=e;
				if(e.face!=""){$("#avatar_image")[0].src=e.face;}
				document.title=e.unick+" "+document.title;
				$("#iUname").text(e.unick);
				$("#iRoomid").text("（"+iRoomID+"）");
				$("#liveTitle").text(e.UserLabel);
				$("#RoomUserID")[0].value=e.uid;
				if(e.pubnotice){$("#PubNotice").html("<a href='"+e.pubnoticehref+"' target=_blank>"+unescape(e.pubnotice)+"</a>");}
				var iStrPriNotice = '<li class="undefined"><span class="t">{1} </span><img src="/images/pixel.gif" style="display:none" class="uIco {2}"><a id="{3}" class="u" href="javascript://" onclick="LinkLayerClick(this)">{4} </a> 对你说：<a href="{6}" target=_blank>{5}</a></li>';
				if(e.prinotice!=""){$("#PriChatList").append($.format(iStrPriNotice,'',GetSendTime,'',e.uid,unescape(unescape(e.unick)),unescape(e.prinotice),e.prinoticehref))}
				if(e.background!=""){$("body").css("background-image","url("+e.background+")");}
				$("body").css("background-attachment",e.backgroundfix);
				if($.browser.msie){
				$("#iBody").css("margin-top",e.styletop);
				}
				else
				{
				$("#iBody").css("margin-top",e.styletop+"px");
				}
			});
			getroominfo();
		},"script");
	}


	
//get top 3 sysgiftrecord
	$.get("/Handle/SysGiftRecord.asp",{ac:"GetSysGiftRecord",n:3,t:GetSendTime},function(){
		//stime,sunick,suid,runick,ruid,sgiftcount,sgiftname,sgiftclass
		var dataObj = eval("("+SGRe+")");
		var iStrSysGiftRecord = '<li>{0}  <a href="/{4}" target="_blank"><strong class="red">{1}</strong><strong class="zi">({2})</strong>  送给 <strong class="red">{3}</strong><strong class="zi">({4})</strong> {5}个{6}</a>  <span class="{7} giftS"><img src="/images/pixel.gif" class="{7} giftSmall2"></span></li>';
		$.each(dataObj.data,function(i,e){
			$("#gxzi1pcy").find("ul").append($.format(iStrSysGiftRecord,e.stime,unescape(unescape(e.sunick)),e.suid,unescape(unescape(e.runick)),e.ruid,e.sgiftcount,unescape(unescape(e.sgiftname)),e.sgiftclass));
			
		});
	},"script");


	

}
});

function ShowPassConfirm()
{
	if(!$("#PassConfirm").length>0){alert('页面被非法修改,现在返回首页!');location.href="/";}
	$("#PassConfirm").css("display","block");
}


function CheckRoomPass()
{
	if(hex_md5($("#PassConfirm_Pass").attr("value"))==PassHash)
	{
		window.clearInterval(IsPass);
		$("#PassConfirm").css("display","none");
	}
	else
	{
		alert("密码错误!");
	}
}

function getgift()
{
	//get top 10 giftrecord
	$.get("/Handle/GiftRecord.asp",{ac:"GetGiftRecord",guid:$("#RoomUserID")[0].value,n:10,t:GetSendTime},function(){
		//i,uid,unick,gclass,gnum
		var dataObj = eval("("+GRe+")");
		var iStrGiftRecord = '<li><p class="name"><span>{0}.</span><a target="_blank" href="/i/v2/User.html?{1}">{2}</a></p><p class="g"><img class="{3}  giftSmall" src="/images/pixel.gif"><span>{4}</span></p></li>';
		$.each(dataObj.data,function(i,e){
			$("#watchGift").find("ul").append($.format(iStrGiftRecord,i+1,e.uid,unescape(unescape(e.unick)),e.gclass,e.gnum));
		});
	},"script");
}

function getfans()
{
	$.get("/Handle/Fans.asp",{ac:"GetFansTop",rid:$("#RoomUserID")[0].value,t:GetSendTime()},function(){
		var iGFAllData = eval("("+iGFAllRe+")");
		var iGFData = eval("("+iGFRe+")");
		var iGFStr = '<li><b class="t{0}">{0}</b><a target="_blank" href="/{1}" class="pic"><img src="{2}"></a><span class="name"><img class="{4}" src="/images/pixel.gif">&nbsp;<a target="_blank" href="/{1}">{3}</a></span><span class="cash"><img src="/images/pixel.gif">{5}</span></li>';
		//get top 6  fans of all 
		$.each(iGFAllData.data,function(i,e){
			var aface =e.uface==""?"/i/v2/images/face.png":e.uface;
			$("#olsuperfans").append($.format(iGFStr,(i+1),e.uroomid,aface,unescape(unescape(e.unick)),e.upaylevelcalss,e.upaynum));
		});
		//get top 6 fans of 30 day
		$.each(iGFData.data,function(j,r){
			var bface =r.uface==""?"/i/v2/images/face.png":r.uface;
			$("#olsuperfans30").append($.format(iGFStr,(j+1),r.uroomid,bface,unescape(unescape(r.unick)),r.upaylevelcalss,r.upaynum));
		});
	},"script");
}


function getroominfo()
{
	//get RoomInfo
	$.get("/Handle/R.asp",{ac:'GetRoomInfo',rid:iRoomID,t:GetSendTime()},function(){
		//face,incomeclass,unick,uid,livetime,rname,fansnum,pubnotice,pubnoticehref,prinotice,prinoticehref,background,backgroundfix,styletop,stylecss,maxnum
		var dataObj = eval("("+iRe+")");
		$.each(dataObj.data,function(i,e){
			if(e.Enable==0){alert('该房间处于禁用状态！');location.href='/';}
			iInfo.IsManager=e.IsManager>0?true:false;
			iInfo.IsZBo=e.isZBo>0?true:false;
			$("#incomeclass")[0].className=e.incomeclass;
			$("#livestartTime").text(e.livetime);
			$("#FansNum").text(e.fansnum);
			e.record!=""?Record=e.record:"";
			e.islive>2?IsLive=false:IsLive=true;
			if(e.attention>0){initFav(true);}else{initFav(false);}
			//stylecss
			AddUserList(iInfo);
			if(parseInt(iRoomID)==parseInt(iInfo.RoomID))
			{$("#ManagerAdminP").css("display","block");$(".btns").css("display","block");}
			else if(iInfo.IsManager)
			{$("#ManagerP").css("display","block");$(".btns").css("display","block");}
			getgift();
			getfans();
		});
	},"script");
}

function getisLive()
{
	$.get("/Handle/R.asp",{ac:'GetRoomInfo',rid:iRoomID,t:GetSendTime()},function(){
		//face,incomeclass,unick,uid,livetime,rname,fansnum,pubnotice,pubnoticehref,prinotice,prinoticehref,background,backgroundfix,styletop,stylecss,maxnum
		var dataObj = eval("("+iRe+")");
		$.each(dataObj.data,function(i,e){
			e.islive>2?IsLive=false:IsLive=true;
			e.record!=""?Record=e.record:"";
			_iLivePlayer._IsLive(IsLive);
			!IsLive?_iLivePlayer._PlayRecord(Record):"";
		});
	},"script");
}