var IsLive=false;
var IsPass;
var PassHash;
$(function(){
if(iRoomID)
{
var iRoom = new Object();
//get static Roominfo
	if(typeof(DRoomJS)!="undefined")
	{
		var DRoomJSObj = eval("("+DRoomJS+")");
		$.each(DRoomJSObj.data,function(i,e){
			iRoom.maxnum=e.maxnum;
			if(e.face!=""){$("#avatar_image")[0].src=e.face;}
			$("#iUname").text(e.unick+"（"+iRoomID+"）");
			$("#liveTitle").text(e.rname);
			$("#RoomUserID")[0].value=e.uid;
			iInfo.Partner=e.uid;
			if(e.pubnotice!=""){$("#PubNotice").html("<a href='"+e.pubnoticehref+"#' target=_blank>"+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,e.unick,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);
				$("input[@type=radio][name=StyleTop][value="+e.styletop+"]").attr("checked","true");
				$("#BackgroundFix")[0].selectedIndex=e.backgroundfix=="fixed"?0:1;
				$("#tPubNotice").text(e.pubnotice);
				$("#tPriNotice").text(e.prinotice);
				$("#tPubNoticeHref").attr("value",e.pubnoticehref);
				$("#tPriNoticeHref").attr("value",e.prinoticehref);
			}
			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;
				if(e.face!=""){$("#avatar_image")[0].src=e.face;}
				$("#iUname").text(e.unick+"（"+iRoomID+"）");
				$("#liveTitle").text(e.rname);
				$("#RoomUserID")[0].value=e.uid;
				if(e.pubnotice){$("#PubNotice").html("<a href='"+e.pubnoticehref+"' target=_blank>"+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,e.unick,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:4,t:GetSendTime},function(){
		//stime,sunick,suid,runick,ruid,sgiftcount,sgiftname,sgiftclass
		var dataObj = eval("("+SGRe+")");
		var iStrSysGiftRecord = '<li><a href="/{4}" target="_blank">{1}<span>({2})</span>  送给 {3}<span>({4})</span> {5}个{6}</a>  <img src="/images/pixel.gif" class="{7} giftSmall">  {0}</li>';
		$.each(dataObj.data,function(i,e){
			$("#gxzi1pcy").find("ul").append($.format(iStrSysGiftRecord,e.stime,e.sunick,e.suid,e.runick,e.ruid,e.sgiftcount,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,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,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,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){
			//iInfo.IsManager=e.IsManager>0?true:false;
			iInfo.IsManager=false;
			$("#incomeclass")[0].className=e.incomeclass;
			$("#livestartTime").text(e.livetime);
			$("#FansNum").text(e.fansnum);
			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");}
			else if(iInfo.IsManager)
			{$("#ManagerP").css("display","block");}
			getgift();
			getfans();
		});
	},"script");
}