// JavaScript Document
function getObject(objectId) {
  if(document.getElementById && document.getElementById(objectId)) {
// W3C DOM
return document.getElementById(objectId);
  } else if (document.all && document.all(objectId)) {
// MSIE 4 DOM
return document.all(objectId);
  } else if (document.layers && document.layers[objectId]) {
// NN 4 DOM.. note: this won't find nested layers
return document.layers[objectId];
  } else {
return false;
  }
}

function shows(Id){getObject(Id).style.display='block';}
function hides(Id){getObject(Id).style.display='none';}


function scrollnews(){
var htext = document.getElementsByTagName("h1"); 
var text_holder = document.getElementById("newscommend");
var oFrag = document.createDocumentFragment();
oFrag.innerHTML="";
for(var i=0;i<htext.length;i++){
	oFrag.innerHTML+=htext[i].innerHTML+"&nbsp;&nbsp;";
	if((i>0 && i%2==1) || (i==htext.length-1 && i%2==0)){
		oFrag.innerHTML+="<br/>";
	}
}
text_holder.innerHTML=oFrag.innerHTML;
}

function ScrollText(content,btnPrevious,btnNext,autoStart,timeout,isSmoothScroll){
	this.Speed = 10;
	this.Timeout = timeout;
	this.stopscroll =false;//是否停止滚动的标志位
	this.isSmoothScroll= isSmoothScroll;//是否平滑连续滚动
	this.LineHeight = 20;//默认高度。可以在外部根据需要设置
	this.NextButton = this.$(btnNext);
	this.PreviousButton = this.$(btnPrevious);
	this.ScrollContent = this.$(content);
	this.ScrollContent.innerHTML += this.ScrollContent.innerHTML;//为了平滑滚动再加一遍
	if(this.PreviousButton){
		this.PreviousButton.onclick = this.GetFunction(this,"Previous"); 
		this.PreviousButton.onmouseover = this.GetFunction(this,"MouseOver");
		this.PreviousButton.onmouseout = this.GetFunction(this,"MouseOut");
	}
	if(this.NextButton){
		this.NextButton.onclick = this.GetFunction(this,"Next");
		this.NextButton.onmouseover = this.GetFunction(this,"MouseOver");
		this.NextButton.onmouseout = this.GetFunction(this,"MouseOut");
    }
    this.ScrollContent.onmouseover = this.GetFunction(this,"MouseOver");
    this.ScrollContent.onmouseout = this.GetFunction(this,"MouseOut");
	
	if(autoStart){
		this.Start();
	}
}

ScrollText.prototype = {
	$:function(element){
		return document.getElementById(element);
	},
	Previous:function(){
		this.stopscroll = true;
		this.Scroll("up");
	},
	Next:function(){
		this.stopscroll = true;
		this.Scroll("down");
	},
	Start:function(){
		if(this.isSmoothScroll){
			this.AutoScrollTimer = setInterval(this.GetFunction(this,"SmoothScroll"), this.Timeout);
		}
		else{		
			this.AutoScrollTimer = setInterval(this.GetFunction(this,"AutoScroll"), this.Timeout);
		}
	},
	Stop:function(){
		clearTimeout(this.AutoScrollTimer);
		this.DelayTimerStop = 0;
	},
	MouseOver:function(){	
		this.stopscroll = true;
	},
	MouseOut:function(){
		this.stopscroll = false;
	},
	AutoScroll:function(){
		if(this.stopscroll) {
			return;
		}
		this.ScrollContent.scrollTop++;
		if(parseInt(this.ScrollContent.scrollTop) % this.LineHeight != 0){
			this.ScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Speed);
		}
		else{
			if(parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2){
				this.ScrollContent.scrollTop = 0;
			}
			clearTimeout(this.ScrollTimer);
			//this.AutoScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Timeout);
		}
	},
	SmoothScroll:function(){
		if(this.stopscroll) {
			return;
		}
		this.ScrollContent.scrollTop++;
		if(parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2){
			this.ScrollContent.scrollTop = 0;
		}
	},
	Scroll:function(direction){
		if(direction=="up"){
			this.ScrollContent.scrollTop--;
		}
		else{
			this.ScrollContent.scrollTop++;
		}
		if(parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2){
			this.ScrollContent.scrollTop = 0;
		}
		else if(parseInt(this.ScrollContent.scrollTop)<=0){
			this.ScrollContent.scrollTop = parseInt(this.ScrollContent.scrollHeight) / 2;
		}
		
		if(parseInt(this.ScrollContent.scrollTop) % this.LineHeight != 0){
			this.ScrollTimer = setTimeout(this.GetFunction(this,"Scroll",direction), this.Speed);
		}
	},
	GetFunction:function(variable,method,param){
		return function(){
			variable[method](param);
		}
	}
}

var lastcsleftClick=null;//上次点击的csleft
window.onload=function(){
	var csleft=document.getElementById("csleft");
	var dls=csleft.getElementsByTagName("dl");
	for (var i=0,dl;dl=dls[i];i++){
		var dt=dl.getElementsByTagName("dt")[0];//取得标题
		dt.id = "csleft_dt_"+(Math.random()*100);
		dt.onclick=function(){
		var p=this.parentNode;//取得父节点
	if (lastcsleftClick!=null&&lastcsleftClick.id!=this.id){
		var dds=lastcsleftClick.parentNode.getElementsByTagName("dd");
		for (var i=0,dd;dd=dds[i];i++)
			dd.style.display='none';
		}
	lastcsleftClick=this;
	var dds=p.getElementsByTagName("dd");//取得该父节点所有的子节点
	var tmpDisplay='none';
		if (gs(dds[0],'display')=='none')
		tmpDisplay='block';
		for (var i=0;i<dds.length;i++)
			dds[i].style.display=tmpDisplay;
			}
	}
}
function gs(d,a){
	if (d.currentStyle){ 
	var curVal=d.currentStyle[a]
	}else{ 
	var curVal=document.defaultView.getComputedStyle(d, null)[a]
	}
	return curVal;
}

function killerrors() {
        return true;
}
window.onerror = killerrors;

