﻿
function MyScroll(div1,div2,height,movePX,speed){
	var layerHeight = height; // 定义滚動区域的高度.
	var iFrame = movePX; // 定义每帧移動的象素.
	var iFrequency = speed; // 定义帧频率.
	var timer; // 定义时间句柄.
	
	if(document.getElementById(div2).offsetHeight >= layerHeight){
		document.getElementById(div1).style.height = layerHeight;
	}else{
		document.getElementById(div1).style.height = document.getElementById(div2).offsetHeight;
	}
	document.getElementById(div1).innerHTML += document.getElementById(div2).innerHTML;
	timer = setInterval(function(){move(div1,div2,iFrame)},iFrequency);
	document.getElementById(div1).onmouseover=function() {clearInterval(timer);}
	document.getElementById(div1).onmouseout=function() {timer=setInterval(function(){move(div1,div2,iFrame)},iFrequency);}


	function move(div1,div2,iFrame){
		var mytop = document.getElementById(div1).scrollTop;
		if( document.getElementById(div1).scrollTop >= document.getElementById(div2).offsetHeight){
			document.getElementById(div1).scrollTop -= (document.getElementById(div2).offsetHeight - iFrame);
		}else {	
			document.getElementById(div1).scrollTop += iFrame;
		}
	}

}


/*
*icefable1 为DIV的ID
*marHeight 为DIV的高度，以及滚動多少像素后等待
*speed 滚動的速度，每秒为1000
*wait_times 为等待的时间，跟speed有关，即滚動多少次后等待
*/
function MyMarquees(icefable,marHeight,speed,wait_times){ 
 var icefable1 = document.getElementById(icefable);

 var marqueesHeight=marHeight;
 var stopscroll=false;
 var timer;
 with(icefable1)
 {
  icefable1.style.height=marqueesHeight;
  icefable1.style.overflow="hidden";
  icefable1.onmouseover=function() {clearInterval(timer)}
  icefable1.onmouseout=function() {timer=setInterval(function(){scrollUp(wait_times);},speed)}
 }
 var preTop=0;
 var currentTop=marqueesHeight;
 var stoptime=0;
 icefable1.innerHTML+=icefable1.innerHTML;

 function init_srolltext()
 {
  icefable1.scrollTop=0;
  timer = setInterval(function(){scrollUp(wait_times);},speed);  //滚動速度
  
 }
 
 
function scrollUp(wait_times){
	if(stopscroll==true) return;
 	currentTop+=1;
	if(currentTop==marqueesHeight+1){
		stoptime+=1;
		currentTop-=1;
	  	if(stoptime==wait_times) {  //设置滚動次数，等待
			currentTop=0;
			stoptime=0;    
			//icefable1.scrollTop+=1;
	   	}
	}else{   
		preTop=icefable1.scrollTop;
		icefable1.scrollTop+=1;
	  	if(preTop==icefable1.scrollTop){
			//alert(preTop);            //查看DIV的最高高度
			icefable1.scrollTop = marqueesHeight;
			icefable1.scrollTop+=1;   
	   }
	}   
 }
 init_srolltext();
}


function MyScrollUp(icefable,marHeight,speed,wait_times){ 
 var icefable1 = document.getElementById(icefable);

 var marqueesHeight=marHeight;
 var stopscroll=false;
 var timer;
 with(icefable1)
 {
  icefable1.style.height=marqueesHeight;
  icefable1.style.overflow="hidden";
  icefable1.onmouseover=function() {clearInterval(timer)}
  icefable1.onmouseout=function() {timer=setInterval(function(){scrollUp(wait_times);},speed)}
 }
 var preTop=0;
 var currentTop=marqueesHeight;
 var stoptime=0;
 var i = 0;
 icefable1.innerHTML+=icefable1.innerHTML;

 function init_srolltext()
 {
  icefable1.scrollTop=0;
  timer = setInterval(function(){scrollUp(wait_times);},speed);  //滚動速度
  
 }
 
 
function scrollUp(wait_times){
	if(stopscroll==true) return;
 	currentTop+=1;
	if(currentTop==marqueesHeight+1){
		stoptime+=1;
		currentTop-=1;
	  	if(stoptime==wait_times) {  //设置滚動次数，等待
			currentTop=0;
			stoptime=0;    
			//icefable1.scrollTop+=1;
	   	}
	}else{   
		preTop=icefable1.scrollTop;
		icefable1.scrollTop+=1;
		i += 1;
	  	if(preTop==icefable1.scrollTop){
			//alert(preTop);            //查看DIV的最高高度
			i += (marqueesHeight + 1);
			i = i/2 - marqueesHeight;
			icefable1.scrollTop = i
			icefable1.scrollTop+=1;   
			i += 1 ;
	   }
	}   
 }
 init_srolltext();
}



function ScrollImgLeft(div1,div2,div3,speed){
	var demo = document.getElementById(div1);
	var demo1 = document.getElementById(div2);
	var demo2 = document.getElementById(div3);
	demo2.innerHTML=demo1.innerHTML;
	function Marquee(){
		if(demo2.offsetWidth-demo.scrollLeft<=0){
			demo.scrollLeft-=demo1.offsetWidth;
		}else{			
			demo.scrollLeft++;
		}
	}
	var MyMar=setInterval(Marquee,speed)
	demo.onmouseover=function() {clearInterval(MyMar)}
	demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
}


function AutoSelect(spacetime){
	timer = setInterval(function(){countTime()},spacetime);
}

function countTime(){
	var count = document.getElementById("count");
	var val = parseInt(count.value);
	setTab("one",val,3);	
	val += 1 ;
	if(val > 3){
		count.value = 1;
	}else{
		count.value = val;
	}
}

function AutoScrollTop(div_content,div_top,top_picture){
	var top = document.getElementById(div_top);
	var right_div = document.getElementById(div_content);
	var top_picture = document.getElementById(top_picture);
	var inc_height = document.documentElement.clientHeight - top.getBoundingClientRect().top - top_picture.offsetHeight;
	timer = setInterval(ChangeTop,1);
	
	function ChangeTop(){
		var height_div = right_div.offsetHeight - top_picture.offsetHeight;
		var long1 = parseInt(document.documentElement.scrollTop);
		if(long1 >= 0){
			if(inc_height+long1 > height_div){
				top.style.paddingTop = height_div + "px";	
			}else{
				top.style.paddingTop = (inc_height + long1) + "px";
			}
		}else{
			top.style.paddingTop = inc_height + "px";
		}
	}
}


//var oMarquee = document.getElementById("demo"); //滚動对象
//var iLineHeight = 42; //单行高度，像素
//var iLineCount = 7; //实际行数
//var iScrollAmount = 1; //每次滚動高度，像素
//function run() {
//oMarquee.scrollTop += iScrollAmount;
//if ( oMarquee.scrollTop == iLineCount * iLineHeight )
//oMarquee.scrollTop = 0;
//if ( oMarquee.scrollTop % iLineHeight == 0 ) {
//window.setTimeout( "run()", 2000 );
//} else {
//window.setTimeout( "run()", 50 );
//}
//}
//oMarquee.innerHTML += oMarquee.innerHTML;
//window.setTimeout( "run()", 2000 );
 



//--------------------------------------------------


/*
marqueeboxId 内容id
wrapBoxHeight 外框高度 用字符串 例如 "200px" 滚完一次后，让它从最下面出来
lh 滚多少个像素后停一下
*/
function startmarquee(marqueeboxId,wrapBoxHeight,lh,speed,delay) {
var t=0;
var o=document.getElementById(marqueeboxId);
if(!o)return;
o.style.marginTop=0;
o.onmouseover=function(){stopMy();}
o.onmouseout=function(){start();}

setTimeout(start,delay);

function start(){
	o.style.marginTop=parseInt(o.style.marginTop)-1+"px";
if (t==0) {
	t=setInterval(scrolling,speed);
}
}

function stopMy(){
	clearInterval(t);
	t=0;
}

function scrolling(){

if(parseInt(o.style.marginTop)%lh!=0){
o.style.marginTop=parseInt(o.style.marginTop)-1+"px";
if(parseInt(o.style.marginTop) <= -o.scrollHeight) o.style.marginTop=wrapBoxHeight;

}else{
	stopMy();
	setTimeout(start,delay);
}
}
}//startmarquee End






/*
不停向左滚動
marqueeboxId 内容id
wrapBoxWidth 外框宽度 用字符串 例如 "200px" 滚完一次后，让它从最右面出来
*/
function startmarqueeLeft(marqueeboxId,wrapBoxWidth,stepLength,speed) {
var t=0;
var o=document.getElementById(marqueeboxId);
if(!o)return;
o.style.marginLeft=0;
o.onmouseover=function(){stopMy();}
o.onmouseout=function(){start();}

setTimeout(start,1000);

function start(){
if (t==0) {
	t=setInterval(scrolling,speed);
}
}

function stopMy(){
	clearInterval(t);
	t=0;
}

function scrolling(){
	o.style.marginLeft=parseInt(o.style.marginLeft)-stepLength+"px";
	if(parseInt(o.style.marginLeft) <= -o.scrollWidth) o.style.marginLeft=wrapBoxWidth;
}
}//startmarqueeLeft End




/*
不停向上滚動  这个占用cpu比较多，可以使用下面的其他函数
marqueeboxId 内容id
wrapBoxHeight 外框宽度 用字符串 例如 "200px" 滚完一次后，让它从最右面出来
*/
function startmarqueeUp(marqueeboxId,wrapBoxHeight,stepLength,speed) {
var t=0;
var o=document.getElementById(marqueeboxId);
if(!o)return;
o.style.marginTop=0;
o.onmouseover=function(){stopMy();}
o.onmouseout=function(){start();}

setTimeout(start,1000);

function start(){
if (t==0) {
	t=setInterval(scrolling,speed);
}
}

function stopMy(){
	clearInterval(t);
	t=0;
}

function scrolling(){
	o.style.marginTop=parseInt(o.style.marginTop)-stepLength+"px";
	if(parseInt(o.style.marginTop) <= -o.scrollHeight) o.style.marginTop=wrapBoxHeight;
}
}//startmarqueeUp End




/*
使内容增加到足够滚動  用在横向滚動
*/
function copyInnerHtml2(wrapBoxId,innerBoxId) {

	var wrapBoxMy=document.getElementById(wrapBoxId);
	if(!wrapBoxMy)return;

	var innerBoxMy=document.getElementById(innerBoxId);
	if(!innerBoxMy)return;

	var m =parseInt(wrapBoxMy.style.width) / innerBoxMy.scrollWidth;
	if (m>parseInt(m)) {
		m=parseInt(m)+1
	} else {
		m=parseInt(m)
	}
	
//	var h = innerBoxMy.scrollWidth;
//innerBoxMy.style.width=(h*m*2)+"px";

var tempStr=innerBoxMy.innerHTML;

	if (m>1) {

		for (var i=1; i < m; i++) {
			tempStr+=innerBoxMy.innerHTML //<tr>等不能运行此句，<ul>可以

		}

		innerBoxMy.innerHTML=tempStr;

	}
	
}//copyInnerHtml2 End




/*
不停向左滚動
*/
function startmarqueeLeft3(marqueeboxId,marqueeboxId2,speed) {


var o=document.getElementById(marqueeboxId);
if(!o)return;

var o2=document.getElementById(marqueeboxId2);
if(!o2)return;

if (o2.scrollWidth < parseInt(o.style.width)) {return;} //当内容太少时是无法滚動的，所以return  //如果.scrollWidth不行就用.style.width 注意width和height不要搞乱

var t=0;

o2.innerHTML+=o2.innerHTML;

//o.style.marginTop=0;
o.onmouseover=function(){stopMy();}
o.onmouseout=function(){start();}

//setTimeout(start,1000);
start();

function start(){
if (t==0) {
	t=setInterval(scrolling,speed);
}
}

function stopMy(){
	clearInterval(t);
	t=0;
}

function scrolling(){
	//	o.style.marginTop=parseInt(o.style.marginTop)-stepLength+"px";
	//	if(parseInt(o.style.marginTop) <= -o.scrollHeight) o.style.marginTop=wrapBoxHeight;
	o.scrollLeft+=1;
	if(o.scrollLeft >= o2.scrollWidth/2) o.scrollLeft=0;
}


}//startmarqueeLeft3 End






/*
向上滚動，滚一定长度然后停一下
*/
function startmarqueeUp3(marqueeboxId,marqueeboxId2,moveLengthMy,speed,delayMy) {

var o=document.getElementById(marqueeboxId);
if(!o)return;

var o2=document.getElementById(marqueeboxId2);
if(!o2)return;

if (o2.scrollHeight < parseInt(o.style.height)) return; //当内容太少时是无法滚動的，所以return  //如果.scrollHeight不行就用.style.height

var t=0;
var i=0;

o2.innerHTML+=o2.innerHTML;

//o.style.marginTop=0;
o.onmouseover=function(){stopMy();}
o.onmouseout=function(){start();}

//setTimeout(start,1000);
start();

function start(){
o.scrollTop+=1;
if (t==0) {
	t=setInterval(scrolling,speed);
}
}

function stopMy(){
	clearInterval(t);
	t=0;
}

function scrolling(){
if(o.scrollTop%moveLengthMy!=0){
		o.scrollTop+=1;
		if(o.scrollTop >= o2.scrollHeight/2) {o.scrollTop=0;}
}else{
		stopMy();
		setTimeout(start,delayMy);
	}
}

}//startmarqueeUp3 End





