/* ======================================================
 * 程序名: Maple Web.CMS (无间断滚动类)
 * 当前版本: v1.0.1 beta1
 * 作者: 云端o枫o0
 * 联系邮件: lantk@126.com
 * 腾讯QQ: 570389199
 * 网站地址: http://lantk.588.net
 * 最后更新: 2007-9-17
 * 注释: 此段代码不会影响程序执行，请尊重作者的劳动，谢谢。
 * =======================================================
 */

function marquee(){
	var timer,obj=this; //时间句柄
	this.waitTime = this.objSize = this.width = this.height = this.direction = this.scrollAmount = this.scrollDelay = this.startID = "";
	this.arrPath = {"up":0,"down":1,"left":2,"right":3}

	this.objID = document.getElementById(arguments[0]); //操作对象
	if(!this.objID){
		alert("对象名【"+ arguments[0] +"】无效，系统无法初始化，请检查对象名称是否正确！");
		this.objID = null; return;
	}else{
		this.objID.noWrap = true;
		this.objID.style.overflow = "hidden";
	}

	this.direction = this.direction==""?0:arguments[1]; //默认方向(Up)
	this.width = this.width==""?this.objID.style.width:arguments[2]; //默认宽度
	this.height = this.height==""?this.objID.style.height:arguments[3]; //默认高度
	this.scrollAmount = this.scrollAmount==""?1:arguments[4] //显示帧数
	this.scrollDelay = this.scrollDelay==""?25:arguments[5] //显示速度
	this.waitTime = this.waitTime<500?500:arguments[6] //运行间隔时间
}

marquee.prototype.start = function(){
	if(this.objID == null){
		return;
	}else{
		var objMarquee = this;
		var timer = this.scrollDelay;
	}
	objMarquee.timeID = null;
	objMarquee.objID.style.width = !isNaN(this.width)?this.width+"px":"auto";
	objMarquee.objID.style.height = !isNaN(this.height)?this.height+"px":"auto";
	objMarquee.direction = typeof(this.direction)=="string"?this.arrPath[this.direction.toString()]:this.direction;

	objMarquee.startID = function(){
		objMarquee.run();
	}

	objMarquee.Begin = function(){
		objMarquee.objSize = objMarquee.direction>1?objMarquee.objID.scrollWidth:objMarquee.objID.scrollHeight;
		objMarquee.objID.innerHTML += objMarquee.objID.innerHTML;
		objMarquee.timeID = setInterval(objMarquee.startID,timer);

		objMarquee.objID.onmouseover = function(){
			clearInterval(objMarquee.timeID);
		}

		objMarquee.objID.onmouseout = function(){
			objMarquee.timeID = setInterval(objMarquee.startID,timer);
		}
	}

	setTimeout(objMarquee.Begin,this.waitTime);
}
marquee.prototype.run = function(){
	switch(this.direction){
		case 0:
			if(this.objID.scrollTop >= this.objSize){
				this.objID.scrollTop -= this.objSize;
			}else{
				this.objID.scrollTop += this.scrollAmount;
			}
			break;
		case 2:
			if(this.objID.scrollLeft > this.objSize){
				this.objID.scrollLeft -= this.objSize;
			}else{
				this.objID.scrollLeft += this.scrollAmount;
			}
			break;
		default:
	}
}