﻿
/*******************************************\
  String 的扩展方法(2006-8-8)
  本文档原作者：zmm，后期修改与补充：dron
  
  功能：滚屏类(2009-09-01)
  本文档作者、开发：宗玓
  版本: V1.0  
\*******************************************/
//当前对象名称,区域ID,
//单行高度,单屏行数,
//单步移动高度,
//时间间隔值,
//暂时时间值
//默认首屏索引
function Marquee(instance,MarqueeBoxID,LineHeight,LineCount,MarqueeStep,MarqueeInterval,MarqueeDelay,ScrollTopLength)
{
	this.Author =(function(){return "Wisdom-Star(宗玓)";})();//属性写法
	this.Version ="1.0";
	this.UpdateTime = "2009年9月1日";
	this.Friend = "流星蝴蝶剑";
		
	this.instance =instance;//实例名称
	this.d = new Date();
	this.oldDate = this.d.getTime();
	this.CurrentDate = this.d.getTime();
	this.IsDelay = false;//是否延迟:即暂停		
	this.marqueeInterval = 50;

	this.marqueeObj = document.getElementById("marqueeBox");//DIV对象
	this.marqueeHeight= 26 * 6; //单行：75；双行：150
	this.marqueeDelay = 5000;//毫秒
	this.marqueeStep = 10;//需为高的公约数
	this.IsMouseOn = false;//如果鼠标在区域上，则设置为 True.
	
	
	this.ScrollTop = function(topValue)
	{
		if(topValue)
		{ 
			var count =(parseInt( this.marqueeObj.scrollHeight / this.marqueeHeight,10)+ 1);
			if(topValue<0 ) topValue = 0; //防止超出。
			else  topValue %= count;
			this.marqueeObj.scrollTop = topValue * this.marqueeHeight; 
		}
		
	};
	this.init(MarqueeBoxID,LineHeight,LineCount,MarqueeStep,MarqueeInterval,MarqueeDelay,ScrollTopLength);
	this.marqueeObj.MySelf = this;

}
//Marquee.prototype.abc = (function(){alert("2009")})();
Marquee.prototype.ShowVersion = function()
{
	var s =   "作　　者：" + this.Author
		+ "\r\n\r\n版　　本：" + this.Version
		+ "\r\n\r\n当前对象：" + this.instance
		+ "\r\n\r\n支　　持：" + this.Friend
		+ "\r\n\r\n最后更新：" + this.UpdateTime;
	alert(s);
}
//区域ID,单行高度,单屏行数,单步移动高度,时间间隔值,暂时时间值,滚动初始值(单屏的倍数值)
Marquee.prototype.init=function(MarqueeBoxID,LineHeight,LineCount,MarqueeStep,MarqueeInterval,MarqueeDelay,ScrollTopLength)
{
		if(MarqueeBoxID) this.marqueeObj = document.getElementById(MarqueeBoxID);//DIV对象
		
		if(LineHeight && LineCount ) this.marqueeHeight = LineHeight * LineCount; 
		
		this.marqueeObj.style.height = this.marqueeHeight;
		this.marqueeObj.style.display="block";
		this.marqueeObj.style.overflow="hidden";
		this.marqueeObj.style.borderWidth="0px";
		this.marqueeObj.style.borderColor="red";
		this.marqueeObj.style.borderStyle="solid";
		
/*	
		var s ="";
		for(var i=1;i<=60;i++)
		{
		 	s +='<div class="shgs_list"><div class="shgs_date" style="margin-left:10px"><a href="#">酸草莓'+ i +'</a>《女性减肥早餐的四大问题》</div></div>';
		}	
		this.marqueeObj.innerHTML = s;*/
		this.marqueeObj.innerHTML = this.marqueeObj.innerHTML + this.marqueeObj.innerHTML;
		this.IsDelay = true;

		this.marqueeObj.onmouseover= function(){this.MySelf.Stop();};
		this.marqueeObj.onmouseout = function(){ this.MySelf.Star();};

		if(MarqueeStep) this.marqueeStep = MarqueeStep;


		this.ScrollTop(ScrollTopLength);
		
		if(MarqueeInterval) this.marqueeInterval = MarqueeInterval;
		if(MarqueeDelay) this.marqueeDelay = MarqueeDelay;
		
		this.startMarquee();
};


Marquee.prototype.MarqueeInterval = function(MarqueeInterval){ Marquee.prototype.marqueeInterval = MarqueeInterval; }
Marquee.prototype.MarqueeHeight = function(LineHeight,LineCount){if(LineHeight && LineCount )  this.marqueeHeight= LineHeight * LineCount; return this.marqueeHeight;}
Marquee.prototype.MarqueeDelay=function(MarqueeDelay){ if(MarqueeDelay)  this.marqueeDelay = MarqueeDelay;return this.marqueeDelay; }
Marquee.prototype.MarqueeStep=function(MarqueeStep){ if(MarqueeStep)  this.marqueeStep = MarqueeStep;return this.marqueeStep; }
Marquee.prototype.startMarquee = function(){this.marqueeInterval=setInterval(this.instance+".scrollMarquee()",this.marqueeInterval );}
Marquee.prototype.stopMarquee = function (){clearInterval(this.marqueeInterval);}
Marquee.prototype.Stop = function(){this.IsMouseOn = true;};
Marquee.prototype.Star = function(){this.IsMouseOn = false;};


Marquee.prototype.scrollMarquee = function () 
{
	if(this.marqueeObj==null)
		return ;
	if( this.IsMouseOn ){return;}
	if(this.IsDelay==true)
	{
		//开始延时:即在延时后将 IsDelay = false;
		this.d = new Date();
		this.CurrentDate= this.d.getTime() ;
		if(this.oldDate + this.marqueeDelay<= this.CurrentDate)				
			this.IsDelay = false;
	}
	else // this.IsDelay = false ;
	{
		this.marqueeObj.scrollTop += this.marqueeStep; //移动 
		this.intTmp = this.marqueeObj.scrollTop % this.marqueeHeight;
		if( this.intTmp>=0 && this.intTmp<this.marqueeStep)
		{
			this.d = new Date();
			this.oldDate= this.d.getTime();        
			this.IsDelay =  true;//确定何时开始延时
		}			
	}	
	//判断是否超出界尺寸
	if(this.marqueeObj.scrollTop >= this.marqueeObj.scrollHeight /2)
	{
		this.marqueeObj.scrollTop = 0;
		//this.d = new Date();
		//this.oldDate= this.d.getTime();        
		this.IsDelay =  true;//确定何时开始延时		
	}	
	
} 




/*
var _x = new Marquee("_x","marqueeBox",26,6,2,10);
//当前对象自己的名称，所操作的区域的ID，单行的高度，所操作的行数，每次移动的距离，时间间隔数。
var _x1 = new Marquee("_x1","marqueeBox1",26,12,2,10);
*/

