//新闻
var newPos = 0;
var moveTime = 0;
function $(id){
	return document.getElementById(id);
}
function showNews(id){
	//
	newPos = id;
	if(newPos == 1){
		moveTime = 8;
	}else{
		moveTime = 3;
	}
	for(var i=1;i<=5;i++){
		$("news_"+i).style.display="none";
		$("nav_"+i).className = "";
		
	}
	$("news_"+id).style.display="block";
	$("nav_"+id).className = "tabon";
	oldClass = "tabon";
}

function moveNews(){
	if(moveTime <= 0){
		doMoveNews();
		//设置下次显示的时间
		if(newPos == 1){
			moveTime = 8;
		}else{
			moveTime = 3;
		}
	}else{
		moveTime = moveTime - 1;
	}
	setTimeout("moveNews()",1000);
}

function doMoveNews(){
	newPos = newPos + 1;
	if(newPos > 5) newPos = 1;
	showNews(newPos);
}

var oldClass;
function activeSpan(obj,cls){
	if(cls){
		oldClass = obj.className;
		obj.className = cls;
	}else{
		obj.className = oldClass;
	}
}

//专家
var t;
var fun;
var demoWidth = 314;
var demoPostion = 0;
function moveLeft(){
	if(demoPostion < getDemoLength() - 3){
		demoPostion = demoPostion + 1;
		//$("demo").style.marginLeft = -(demoPostion * demoWidth);
		if(!moving){
			moving = true;
			moveTo();
			if(t){
				clearTimeout(t);
			}
			t = setTimeout("moveLeft()",5000);
			fun = "moveLeft()";
		}
	}
	else{
		moveRight();
	}
}

function moveRight(){
	if(demoPostion > 0){
		demoPostion = demoPostion - 1;
		//$("demo").style.marginLeft = -(demoPostion * demoWidth);
		if(!moving){
			moving = true;
			moveTo();
			if(t){
				clearTimeout(t);
			}
			t = setTimeout("moveRight()",5000);
			fun = "moveRight()";
		}
	}else{
		moveLeft();
	}
}
function getDemoLength(){
	var length = 0;
	for(var i=0;i<$("demo").childNodes.length;i++){
		if($("demo").childNodes[i].tagName == "DIV"){
			length++;
		}
	}
	return length;
}

var moving = false;
var margin = 0;
function moveTo(position){
	if(moving){
		if(margin >= -(demoPostion * demoWidth)){
			//
			margin = margin - 4;
			$("demo").style.marginLeft =  margin + "px";
			//alert($("demo").style.marginLeft+"+"+-(demoPostion * demoWidth));
			if(margin < -(demoPostion * demoWidth)){
				moving = false;
			}
		}else{
			//
			margin = margin + 4;
			$("demo").style.marginLeft =  margin + "px";
			if(margin > -(demoPostion * demoWidth)){
				moving = false;
			}
		}
		setTimeout("moveTo()",2);
	}
}

