var scrollinterval = null;
var stepinterval = null;
var firstClick = true;
var step = 0;
var stepnum = 8;
var rowcount = 3;		//滚动行数
var l = true;				//是否连续滚动
var delay = 2500;   //两行之间滚动延迟时间
var beforeStep = null;

//startMoveText，调用的函数，iDirx滚动方向1：向下，2向上
//ji=true连续滚动,false单步滚动
function startMoveText(iDirx,ji){
	  l = ji;
	  beforeStep = iDirx;
	  if (scrollinterval == null){
		  if (iDirx == 1)
	      scrollinterval = setInterval("moveText(1)",1000);
	    else
	    	scrollinterval = setInterval("moveText(2)",1000);
    }
	//stepnum = 8;
	//step = 0;
}
//clickMoveText,按钮点击文字滚动函数，iDirx滚动方向1：向下，2向上
function clickMoveText(iDirx){
	 l = false;
	 if (scrollinterval != null)
	   clearInterval(scrollinterval);
	 if (iDirx == 1){    
	 	  if (beforeStep == 2){
	 	  	step ++
	    	step = ((step > rowcount)?0:step);
	    }	    
	    stepnum = (((step == 0) && (!firstClick))?28:stepnum);
	    step = (((step == 0) && (firstClick))?1:step);		    
	    beforeStep = 1;
	 } else{
	    //stepnum = (((step == 0) && (!firstClick))?25:stepnum);
	    //step = (((step == 0) && (firstClick))?1:step);
	    if (beforeStep == 1)
	      step --;
	    if (step < 0){
	    	 step = rowcount;
	    	 stepnum = -28 * rowcount;
	    }  
	    beforeStep = 2;
	    
	 }
	 firstClick = false;
	 moveText(iDirx);
}
function stopMoveText(){
	 if (scrollinterval != null)
	    clearInterval(scrollinterval);
	 scrollinterval = null;   
}
function moveText(iDirx){
    tagul = document.getElementById('rolltext');
	if (iDirx == 1){
		 if (stepinterval == null)
	   	  stepinterval = setInterval("scrollText(1)",10);  
	} else {
		 if (stepinterval == null)
	   	  stepinterval = setInterval("scrollText(2)",10);  
	}
	clearInterval(scrollinterval);
  scrollinterval = null;
}
function scrollText(iDirx){
    if (iDirx == 1){
	   if (stepnum > 7 - 28 * step){
	      tagul.style.marginTop = stepnum + 'px';
		  stepnum --;
	   } else {
	      clearInterval(stepinterval);
	      stepinterval = null;
				if (step < rowcount)
				   step++;
				else{
				   step = 0; 
				   stepnum = 28;
				} 	 	      
	      if (l)
		       scrollinterval = setInterval("moveText(1)",delay);
	   }  
	} else {
	   if (stepnum < -28 * (step-1) + 7){
	     tagul.style.marginTop = stepnum + 'px';
	     stepnum ++;
	   } else {
	   	 clearInterval(stepinterval);
	   	 stepinterval = null;
		   if (step > 0)
		      step -- ;
		   else{
		   	  step = rowcount;
		   	  stepnum = -28 * rowcount;
		   } 	   	 
	   	 if (l)
	   	    scrollinterval = setInterval("moveText(2)",delay);
	   }
	}
}
