var lh=location.href,gTab=0;
var gData=[["http://web.qbar.qq.com","act/web","http://web.qbar.qq.com/dzh/dzhtuijian.htm","大杂烩","http://adsview.qq.com/adsview?c=qzone&l=Qbar_Second_Width&log=off"],["http://qbarzh.games.qq.com","act/game","http://games.qq.com/gameqbar/qbar_right.shtml","游戏杂烩","http://games.qq.com/gameqbar/qbar_left.htm"],["http://comic.qbar.qq.com","act/comic","http://comic.qq.com/comicbbs/comicqbar.htm","动漫杂烩","http://bbs1.qq.com/dazahui_comic.html"],["http://qbarzh.tech.qq.com","act/tech","http://digi.tech.qq.com/qba/digiqbar.htm","数码杂烩","http://digi.tech.qq.com/qba/qbarleft.htm"],["http://qbarzh.sports.qq.com","act/sports","http://sports.qq.com/sportsqbar/bardzh/index.htm","体育杂烩","http://bbs1.qq.com/dazahui_web.html"],["http://qbarzh.edu.qq.com","act/edu","http://edu.qq.com/xyqbar/xyqbar_right.htm","高校杂烩","http://bbs1.qq.com/dazahui_young.html"],["http://512.qbar.qq.com","act/web","http://bbs1.qq.com/512dizhen.shtml","纪念512","http://bbs1.qq.com/512zt.shtml"],["http://qbarzh.auto.qq.com","act/web","http://auto.qq.com/qbarright/index.htm","汽车杂烩","http://auto.qq.com/qbarright/ggb.htm"],["http://qbarzh.lady.qq.com","act/web","http://lady.qq.com/zhuant/zhuant3/ladyzh.htm","女性杂烩","http://bbs1.qq.com/dazahui_lady.html"],["http://qbarzh.astro.qq.com","act/web","http://astro.lady.qq.com/qbar/qbar_dzh.htm","星座杂烩","http://bbs1.qq.com/dazahui_astro.html"],["http://qbarzh.ent.qq.com","act/web","http://ent.qq.com/zt/2008/qbyl/qbarent.htm","娱乐杂烩","http://bbs1.qq.com/dazahui_ent.html"]];
for (var i=0; i<gData.length; i++){
	if (lh.indexOf(gData[i][0])>-1){
		gTab=i;
		break;
	}
}
var gDialogObj=null,gDialogWin=null,gLFRow=null,gActLocation=gData[gTab][1];
function $(d){return document.getElementById(d)}
function IsInObj(nObj,oObj){
	if (typeof(oObj)=="string"?nObj.id==oObj:nObj==oObj) return true
	var p=nObj.parentNode;
	if(p) return IsInObj(p,oObj)
	return false
}
function HideDialogWin(){
	if (!gDialogWin) return
	gDialogWin.style.display='none';
	gDialogObj=null;
	gDialogWin=null;
}
function GetEvent(){
	if(T.isIE) return window.event;
	var func=GetEvent.caller;           
	while(func!=null){    
		var Y=func.arguments[0];
		if(Y){
			if((Y.constructor==Event||Y.constructor==MouseEvent)||(typeof(Y)=="object" && Y.preventDefault&&Y.stopPropagation)){return Y}
		}
		func=func.caller
	}
	return null
}
function LoadAtcl(){
	var e=GetEvent(),obj=e.srcElement||e.target;
	if(e.preventDefault) e.preventDefault()
    else e.returnValue=false

	var arg=obj.getAttribute('href').replace(/.*\?/,''),cf=window['DOMcf'];
	try{
		var a=cf.location.pathname;
		var path=a.replace(/.*\//ig,'').replace(/\#.*/,'')
	}
	catch(e){cf.location.href='http://web.qbar.qq.com/dzh/r.htm#'+arg}
	if (path!='r.htm'){
		cf.location.href='http://web.qbar.qq.com/dzh/r.htm#'+arg
	}else{
		cf.location.hash=arg;
		cf.LoadAtcl()
	}
	location.hash=obj.href.replace(/.*(\?|#)/g,'');

	while (obj.nodeName.toLowerCase()!="li"){obj=obj.parentNode}
	if (gLFRow) gLFRow.style.backgroundColor=""
	gLFRow=obj;
	obj.style.backgroundColor="#9FC5FF"
}
var gAliveDays=0,gAliveScore=0;
function Init(){
	gAliveDays=0,gAliveScore=0;
	var uin=T.GetUIN();
	if (uin>10000){
		T.LoadData("http://mng.qbar.qq.com/cgi-bin/cafe_ustat_cgi_view.cgi?uin="+uin,
			function(R){
				gAliveDays=R.uinfos[0].o;
				gAliveScore=R.uinfos[0].s;
				Start()
			},Start
		)
	}else{
		Start()
	}
}
function Start(){
	var initpage="";
	if (location.hash.length>1 || location.search>1){
		var parstr=window.location.href.replace(/.*(\?|#)/g,'');
		initpage='http://web.qbar.qq.com/dzh/r.htm#'+parstr.split("&")[0];
	}else{
		initpage=gData[gTab][2];
	}
	window['DOMcf'].location.href=initpage;
	BodyAutoHeight();
	lastActive=$('DOM_LDiv1').getElementsByTagName('A')[0];
	if($('D_navStyleCtl')){$('D_navStyleCtl').onclick=SwitchPage}
	window.onresize=BodyAutoHeight;

	var lis=$("DOM_mContent").getElementsByTagName("li"),item;
	for (var i=0,len=lis.length;i<len;i++){
		item=lis[i].getElementsByTagName("a");
		if (item.length>0){item[0].attachEvent("onclick",LoadAtcl)}
	}
	document.body.attachEvent("onclick",function(e){
		e=window.event||e;
		var obj=e.srcElement||e.target;
		if (gDialogObj!=obj && !IsInObj(obj,gDialogWin))HideDialogWin()
	});
	SetPager(1);
	var sh=$("SearchSwitch");
	sh.attachEvent("onmouseover",SMenuShow);
	sh.attachEvent("onmouseout",SMenuHide);
	var smenu=$("SearchMenu"), lis=smenu.getElementsByTagName("li");
	smenu.attachEvent("onmouseover",SMenuShow);
	smenu.attachEvent("onmouseout",SMenuHide);
	for (var i=0,len=lis.length;i<len;i++){
		item=lis[i]
		item.attachEvent("onmouseover",function(e){
			e=window.event||e;
			var obj=e.srcElement||e.target;
			obj.className+=" hover"
		});
		item.attachEvent("onmouseout",function(e){
			e=window.event||e;
			var obj=e.srcElement||e.target;
			obj.className=obj.className.replace(/\s*hover/ig,"");
		});
		item.attachEvent("onclick",function(e){
			SMenuHide(1);
			e=window.event||e;
			var obj=e.srcElement||e.target;
			setTimeout(function(){$("btnSeach").innerHTML=obj.innerText},100)
		});
	}
	BindSlide();
	window['D_banner1'].location.href="http://bbs1.qq.com/dzhgonggao.htm";
	window['D_banner2'].location.href=gData[gTab][4];
}
var gMenuTimer=null;
function SMenuShow(){
	var sh=$("SearchSwitch"),smenu=$("SearchMenu");
	if (smenu.style.display=="none"){
		var d=GetPositionOnPage(sh);
		smenu.style.left=(d.x-45)+"px";
		smenu.style.top=d.y+GetOffset(sh).height-(T.isIE?5:1)+"px";
	}
	smenu.style.display="block";
	clearTimeout(gMenuTimer)
}
function SMenuHide(a){
	var b=a||300;
	var smenu=$("SearchMenu");
	gMenuTimer=setTimeout(function(){smenu.style.display="none"},b)
}
function SwitchPage(){
	var cel=$('DOM_mainTable').rows[0].cells;
	cel[0].swapNode(cel[2]);
	this.innerText=(this.innerText.indexOf('右')>0?'导航在左':'导航在右');
}
function go(){
	var lefttd=$('DOM_leftTD'),isShow=(lefttd.style.display=="");
	lefttd.style.display=isShow?"none":"";
	$('chead').childNodes[0].style.backgroundPosition=isShow?"left":"right";
}
function BindSlide(){
	var n=500,dragok=false,y,x,d,dy,dx,shadowTimer;
	function move(e){
		e=window.event||e;
		if (dragok){
			var mainstyle=$('main').style;
			try{
				var left=dx+e.clientX-x;
				if (left<160||left>750){
					mainstyle.border='1px dashed #D0D8D9';
					return
				}else{
					mainstyle.border=''
				}
				mainstyle.left=left;
				mainstyle.position="absolute";
				$('chead').style.display='none';
				return false
			}catch(e){}
		}
	}
	function down(e){
		e=window.event||e;
		var obj=e.srcElement||e.target;
		if (obj.nodeName.toLowerCase()!="html"|"body" && obj.className!="dragclass"){obj=obj.parentNode}
		if(obj.nodeName.toLowerCase()=="tr"){
			obj=obj.parentNode;
			obj=obj.parentNode;
			obj=obj.parentNode;
		}
		if (obj.className=="dragclass"){
			dragok=true;
			obj.style.zIndex=n;
			d=obj;
			dx=_getoffset(obj)[1];
			dy=_getoffset(obj)[0];
			x=e.clientX;
			document.onmousemove=move;
			shadowTimer=window.setTimeout(function(){$('DOM_shadow').style.zIndex=100},150);
			return false
		}
	}
	function up(){
		var main=$('main'),chead=$('chead'),lefttd=$('DOM_leftTD'),leftcont=$('DOM_LContent');
		if (dragok){
			window.clearTimeout(shadowTimer);
			$('DOM_shadow').style.zIndex=-10;
			chead.style.display='';
			main.style.height="100%";
			main.style.border='';
			main.style.position="static";
			if (lefttd.style.display=="none"){
				lefttd.style.display="";
				chead.childNodes[0].style.backgroundPositionX='right'
			}
		}
		try{
			lefttd.style.width=leftcont.style.width=parseInt(main.style.left)+"px";
			var banner=window["D_banner1"].document.getElementById('D_banner1');
			if (banner.style.display==""){
				banner.style.left=parseInt($('D_banner1').clientWidth)-20+"px"
			}
		}catch(e){}
		dragok=false;
		document.onmousemove=null;
	}        
	document.onmousedown=down;
	document.onmouseup=up;

	function _getoffset(e){ 
		var t=e.offsetTop,l=e.offsetLeft;
		while(e=e.offsetParent){ 
			t+=e.offsetTop;
			l+=e.offsetLeft 
		}
		return [t,l]
	}
}
function SetPager(n){
	if (gTab==0){
		var i=0,html=[];
		while(i++<5){
			html.push((i!=n)?"<a onclick='GOPager("+i+")'><u>":"<span class='bold'>");
			html.push("第"+i+"页");
			html.push((i!=n)?"</u></a>　　":"</span>　　");
		}
		var p2=$('DOM_lPager2');
		p2.style.display="block";
		p2.innerHTML=html.join("");
	}
	if ($('D_sortCtl'))$('D_sortCtl').style.display='inline';
}
function GOPager(n){
	$("DOM_LContent").scrollTop=0;
	var val=$('D_changeSort').value;
	SetPager(n);
	GoWhere("http://"+location.hostname+"/"+gActLocation+"/"+val+"_"+n+".html");
	CurrentPage=n;
}
function BodyAutoHeight(){
	var ch=document.body.clientHeight;
	$('DOM_LContent').style.height=ch-115;
	$('DOM_mainTable').style.height=ch-60;
}
function ViewMyProfile(obj){
	if (T.GetUIN()>10000){
		obj.href='http://user.qbar.qq.com/'+T.GetUIN()+'/';
		return true
	}else{
		T.CreateLoginFrameWin();
		return false
	}
}
var LastItem="D_viewall",CurrentPage=1,request=false;
function GoWhere(dis){
	if(window.XMLHttpRequest) {
		request=new window.XMLHttpRequest();
	}else if (window.ActiveXObject) {
		request=new window.ActiveXObject('Microsoft.XMLHTTP');
	}
	if(request){
		request.onreadystatechange=ProcessReady;
		request.open('GET',dis,true);
		request.send(null);
	}
	var url='/'+dis.replace('http://'+location.hostname+'/','');
	T.PingPGV(1500,url);
}
function GetLoadingDiv(){
	var d=$("loading");
	if (!d){
		d=document.createElement("DIV");
		d.id="loading";
		var s=d.style;
		s.position="absolute";
		s.fontSize="12px";
		s.background="#68AF02";
		s.width="220px";
		s.height="23px";
		s.lineHeight="23px";
		s.top="26px"
		s.left="50%";
		s.marginLeft="-110px";
		s.textAlign="center";
		s.zIndex="100";
		s.color="#FFF"
		s.display="";
		d.innerHTML="正在加载数据...";
		document.body.appendChild(d);
	}else{
		d.style.color="#FFF";
		d.style.background="#68AF02";
		d.innerHTML="正在加载数据...";
		d.style.display=""
	}
}
function SetOpacity(a,b){
	var c=a.style;
    if("filter"in c) c.filter="alpha(opacity="+b*100+")"
    else if("MozOpacity"in c) c.MozOpacity=b
	else if("opacity"in c) c.opacity=b
	else if("KhtmlOpacity"in c) c.KhtmlOpacity=b
}
function ProcessReady(){
	switch (request.readyState){
		case 1:
			GetLoadingDiv();
			break;
		case 4:
			$("loading").style.display="none";
			if (request.status==200||request.status==304){
				$("DOM_LContent").scrollTop=0;
				$('DOM_mContent').innerHTML=request.responseText;
				var lis=$("DOM_mContent").getElementsByTagName("li"),item;
				for (var i=0,len=lis.length;i<len;i++){
					item=lis[i].getElementsByTagName("a");
					if (item.length>0){item[0].attachEvent("onclick",LoadAtcl)}
				}
			}else{
				alert("error");
			}
			break;
	}
}
var lastActive;
function ViewPhotoAtcl(obj){
	ViewHelper(obj);
	GoWhere("http://"+location.hostname+"/"+gActLocation+"/photo_1.html");
	$('D_sortCtl').style.display=$('DOM_lPager2').style.display="none";
}
function ViewVideoAtcl(obj){
	ViewHelper(obj);
	GoWhere("http://"+location.hostname+"/"+gActLocation+"/video_1.html");
	$('D_sortCtl').style.display=$('DOM_lPager2').style.display="none";
}
function ViewAll(obj){
	ViewHelper(obj);
	GOPager(CurrentPage);
}
function ViewHelper(obj){
	lastActive.className='href';
	lastActive=obj;
	obj.className='href active';
}
function ToFresh(){
	if(lastActive==$('D_viewAll'))ViewAll(lastActive);
	else if(lastActive==$('D_viewPhoto'))ViewPhotoAtcl(lastActive);
	else if(lastActive==$('D_viewVideo'))ViewVideoAtcl(lastActive);
}
function ChangeSort(obj){
	obj.disabled=true;
	GOPager(1);
	window.setTimeout(function(){obj.disabled=false},1000);
}
function Search(){
	var kw=$("skw");
	if (kw.value.trim2()!=""){
		var btn=$("btnSeach");
		var t=(btn.innerText.indexOf("Q")>-1)?"bar":"cont";
		var str="http://web.qbar.qq.com/search/?"+t+"="+kw.value.URI();
		if (T.isIE){
			var a=document.createElement("A");
			a.href=str;
			a.target='_blank';
			document.body.appendChild(a);
			a.click();
			a.removeNode(true);
		}else{window.open(str)}
	}
}
function GetOwnerDocument(a){return a.nodeType==9?a:a.ownerDocument||a[document]}
function GetDocumentElement(a){
    var b;
    if (a){b=(a.nodeType==9)?a:GetOwnerDocument(a)}
    else {b=DocObj().T()}
	if(T.isIE&&b.compatMode!="CSS1Compat") return b.body
	return b.documentElement
}
function GetOffset(a){
	if(a.style.display!="none"){
        return {
            'width':a.offsetWidth,
            'height':a.offsetHeight
        }
	}
	var b=a.style,c=b.visibility,d=b.position;
	b.visibility="hidden";
	b.position="absolute";
	b.display="";
	var f=a.offsetWidth,e=a.offsetHeight;
	b.display="none";
	b.position=d;
	b.visibility=c;
	return {
        "width:":f,
        "height:":e
    }
}
function GetPositionOnPage(a){
	var b=GetOwnerDocument(a),c={x:0,y:0},d=GetDocumentElement(b),f=null,e;
	if(a==d){return c}
	if(a.getBoundingClientRect){
		e=a.getBoundingClientRect();
		c.x=e.left+d.scrollLeft;
		c.y=e.top+d.scrollTop
	}
	else{
		c.x=a.offsetLeft;
		c.y=a.offsetTop;
		f=a.offsetParent;
		if(f!=a){
			while(f){
				c.x+=f.offsetLeft;
				c.y+=f.offsetTop;
				f=f.offsetParent
			}
		}
	}
	return c
}