function scrollObj(obj)
{

	//容器相关属性
	//this.boxID = "scrollBox"; //容器ID
	this.boxID =obj;
	//滚动属性
	this.dataSource = "";     //内容数据源
	this.interval  = 3;       //停顿间隔时间 (单位:秒)
	this.speed = 1;          //滚动速度 如果为0则瞬间出现 (单位:毫秒)
	this.dataCount = 10;      //每批条数 如果为0则全部出现
	this.direction = "up";    //滚动方向 up|down|left|right
	//滚动控制
	this.start = function(obj){ //开始滚动
		timeObj = setInterval("move("+obj+")",this.interval);
	}
	this.stop = function(obj){ //停止滚动
		clearInterval(timeObj);
	}
}
function move(obj)
{
	var whichEle = document.getElementById(obj.id);
	if(whichEle.scrollHeight - whichEle.scrollTop == whichEle.clientHeight){
		whichEle.scrollTop = 0;
	}
	else{
		whichEle.scrollTop += 1;
	}		
}
//滚动开关 (参数 open | close)
function scrollSwitch(args,obj)
{
	
	var myScroll = new scrollObj(obj);
	if (args=="start")
	{
		myScroll.start(obj);
	}
	else if (args=="stop"){
		myScroll.stop(obj);
	}
	else{
		alert("错误的输入参数！");
	}
}
function scrollall(){
	scrollSwitch('start','scrollBox');
	scrollSwitch('start','scrollBox1');
}
/////////////////////////////
function scrollObj()
{
	//容器相关属性
	//===============================================================
	this.boxID = "scrollBox"; //容器ID
	
	this.cttHeadHeight = 0;   //滚动内容的头高度 （纵向滚动时调用）
	this.cttBodyHeight = 20;  //滚动内容循环体高度
	this.cttBottomHeight = 0; //滚动内容的尾高度
	this.cttHeadWidth = 0;    //滚动内容的头宽度 （横向滚动时调用）
	this.cttBodyWidth = 20;   //滚动内容循环体宽度
	this.cttBottomWidth = 0;  //滚动内容的尾宽度
	this.bodyCount = 2;       //每周期包含循环体数量

	this.direction = "up";    //滚动方向 up|down|left|right
	this.cycle = 3000;        //周期 (单位:毫秒) 一个周期包括了切换--滚动--停顿3过程
	this.scrollTime = 1000;   //滚动时间 (单位:毫秒)应该小于cycle的值
	//=================================================================	
	//开关控制
	//=================================================================
	this.start = function()//开始切屏
	{ 
		changeScreen(this.boxID,this.cttHeadHeight,this.cttBodyHeight,this.cttBottomHeight,this.cttHeadWidth,this.cttBodyWidth,this.cttBottomWidth,this.bodyCount,this.direction,this.cycle,this.scrollTime)
		timeObj = setInterval("changeScreen('"+this.boxID+"',"+this.cttHeadHeight+","+this.cttBodyHeight+","+this.cttBottomHeight+","+this.cttHeadWidth+","+this.cttBodyWidth+","+this.cttBottomWidth+","+this.bodyCount+",'"+this.direction+"',"+this.cycle+","+this.scrollTime+")",this.cycle);
	}
	
	this.stop = function()//停止切屏
	{ 
		clearInterval(timeObj);
	}	
	//==================================================================
}
//切屏
function changeScreen(boxID,headHeight,bodyHeight,bottomHeight,headWidth,bodyWidth,bottomWidth,bodyCount,direction,cycle,scrollTime)
{

var whichEle = document.getElementById(boxID);
var length = 0;
	switch(direction){
		case "up":
			if(whichEle.scrollTop>=headHeight)//判断循环头是否已滚过
			{
				length = bodyCount * bodyHeight;
			}
			else{
				length = bodyCount * bodyHeight + headHeight;
			}
			move(boxID,"up",whichEle.scrollTop,length,scrollTime);
		break;
		case "down":		
		break;
		case "left":
		
		break;
		case "right":
		
		break;
	}
}
//滚动(容器ID，滚动方向，滚动前屏幕外距离，需要滚动的距离，滚动总时间)
var moveTimeObj;
function move(boxID,direction,sLength,length,scrollTime)
{

	var whichEle = document.getElementById(boxID);
	switch(direction)
	{
		case "up":
			if (whichEle.scrollTop < (sLength+length))
			{
				if(whichEle.scrollTop==parseInt(whichEle.scrollHeight/2))
				{
					whichEle.scrollTop = 0;
					return;
				}
				else
				{
					whichEle.scrollTop += 1;
					moveTimeObj=window.setTimeout(function(){move(boxID,direction,sLength,length,scrollTime)},parseInt(scrollTime/length));
				}
			}
			else{
				clearTimeout(moveTimeObj);
				return;
			}
		break;
		case "down":
		break;
		case "left":
		break;
		case "right":
		break;	
	}
		
}

