

function StartRollRight(objName){
	this.StopRoll();
	this.RollStat = 'Right';
	this.Init();
	this.StartRoll(objName);

}

function StartRollLeft(objName){
	this.StopRoll();
	this.RollStat = 'Left';
	this.Init();
	this.StartRoll(objName);

}

function StartRollUp(objName){
	this.StopRoll();
	this.RollStat = 'Up';
	this.Init();
	this.StartRoll(objName);

}

function StartRollDown(objName){
	this.StopRoll();
	this.RollStat = 'Down';
	this.Init();
	this.StartRoll(objName);

}

function StartRoll(objName){
	this.intervalID = window.setInterval(objName + ".Roll" + this.RollStat + "()", this.pausebetweenitems);
}

function StopRoll(){
	window.clearInterval(this.intervalID);
}

function RollLeft(){
	var peritem;
	for (var n = 0; n < this.Pos.length; n++)
	{
		this.Pos[n] = this.Pos[n] - this.RollStep;
		peritem = n - 1;
		if (peritem < 0 ) peritem = this.Pos.length -1;
		if (this.Pos[n] <= ((this.divwidth+this.Hspace)+this.RollStep) * -1)
		{
			this.Pos[n] = this.XMax + this.X0;
			this.Top[n].left = this.Pos[n];
		}
		else
		{
			if (this.Pos[n] >= this.XMax - (this.divwidth+this.Hspace) )
			{
				
				if (this.Pos[peritem] <= this.XMax - (this.divwidth+this.Hspace))
					this.Top[n].left = this.Pos[n];
				else
					this.Pos[n] = this.XMax;
			}
			else
			{
				this.Top[n].left = this.Pos[n];
			}
		}
	}
}

function RollRight(){
	var peritem;
	for (var n = 0; n < this.Pos.length; n++)
	{
		this.Pos[n] = this.Pos[n] + this.RollStep;
		peritem = n + 1;
		if (peritem >= this.Pos.length ) peritem = peritem - this.Pos.length;
		if (this.Pos[n] >= this.XMax + (this.divwidth+this.Hspace) + this.RollStep )
		{
			this.Pos[n] = this.X0 - (this.divwidth+this.Hspace);
			this.Top[n].left = this.Pos[n];
		}
		else
		{
			if (this.Pos[n] >= this.X0 - (this.divwidth+this.Hspace) && this.Pos[n] < 0)
			{
				
				if (this.Pos[peritem] > 0)
					this.Top[n].left = this.Pos[n];
				else
					this.Pos[n] = this.X0 - (this.divwidth+this.Hspace) ;
					this.Top[n].left = this.Pos[n];this.Top[n].left = this.Pos[n];
			}
			else
			{
				this.Top[n].left = this.Pos[n];
			}
		}
	}
}

function RollUp(){
	var peritem;
	for (var n = 0; n < this.Pos.length; n++)
	{
		this.Pos[n] = this.Pos[n] - this.RollStep;
		peritem = n - 1;
		if (peritem < 0 ) peritem = this.Pos.length -1;
		if (this.Pos[n] <= ((this.divheight+this.Vspace)+this.RollStep) * -1)
		{
			this.Pos[n] = this.YMax + this.Y0;
			this.Top[n].top = this.Pos[n];
		}
		else
		{
			if (this.Pos[n] >= this.YMax - (this.divheight+this.Vspace) )
			{
				
				if (this.Pos[peritem] <= this.YMax - (this.divheight+this.Vspace) )
					this.Top[n].top = this.Pos[n];
				else
					this.Pos[n] = this.YMax;
			}
			else
			{
				this.Top[n].top = this.Pos[n];
			}
		}
	}
}

function RollDown(){
	var peritem;
	for (var n = 0; n < this.Pos.length; n++)
	{
		this.Pos[n] = this.Pos[n] + this.RollStep;
		peritem = n + 1;
		if (peritem >= this.Pos.length ) peritem = peritem - this.Pos.length;
		if (this.Pos[n] >= this.YMax + (this.divheight+this.Vspace) + this.RollStep )
		{
			this.Pos[n] = this.Y0 - (this.divheight+this.Vspace);
			this.Top[n].top = this.Pos[n];
		}
		else
		{
			if (this.Pos[n] >= this.Y0 - (this.divheight+this.Vspace) && this.Pos[n] < 0)
			{
				
				if (this.Pos[peritem] > 0)
					this.Top[n].top = this.Pos[n];
				else
					this.Pos[n] = this.Y0 - (this.divheight+this.Vspace) ;
					this.Top[n].top = this.Pos[n];this.Top[n].top = this.Pos[n];
			}
			else
			{
				this.Top[n].top = this.Pos[n];
			}
		}
	}
}

function ShowMarquee(objName){
	var stronevent
	if (ShowMarquee.arguments.length==0 || objName=='')
	{
		objName='';
		stronevent = '';
	}
	else
	{
		stronevent = 'onmouseover="'+objName+'.StopRoll();" onmouseout="'+objName+'.StartRoll(\''+objName+'\');"';
	}

	if (document.all){
		document.writeln('<span id="main2" style="position:relative;width:'+this.scrollerwidth+';height:'+this.scrollerheight+';overflow:hiden;background-color:'+this.scrollerbgcolor+'">')
		document.writeln('<div style="position:absolute;width:'+this.scrollerwidth+';height:'+this.scrollerheight+';clip:rect(0 '+this.scrollerwidth+' '+this.scrollerheight+' 0);left:0;top:0">')

		for (var loop=0 ; loop < this.slideitems.length;loop++){
			document.writeln('<div id="div' + this.name + loop + '" style="position:absolute;width:'+this.divwidth+';left:' + loop * this.divwidth + ';top:0;" ' + stronevent + '>')
			document.write(this.slideitems[loop])
			document.writeln('</div>')
		}
		document.writeln('</div>')
		document.writeln('</span>')
	}
	else{
		document.writeln('<ilayer id="main2" width='+this.scrollerwidth + '; height='+this.scrollerheight+'; bgColor='+this.scrollerbgcolor+'; visibility=hide">')
		for (var loop=0 ; loop < this.slideitems.length;loop++){
			document.writeln('<layer id="div' + this.name + loop + '" width='+this.divwidth+';left=0 top=0 onmouseover="StopRoll();" onmouseout="StartRoll();">')
			document.write(this.slideitems[loop])
			document.writeln('</layer>')
		}
		document.writeln('</ilayer>')
	}

	this.Init();
}

function InitPos(){
	this.Y0 = 0;
	this.X0 = 0;
	this.XMax = this.scrollerwidth;
	this.YMax = this.scrollerheight;
		
	for (var loop = 0; loop < this.slideitems.length; loop++) {
		if (document.layers) {
			this.Top[loop] = document.layers["div"+ this.name +loop];
		} else if (document.all) {
			this.Top[loop] = document.all("div"+ this.name +loop).style;
		}
	switch (this.RollStat)
	{
	case 'Right':
	case 'Left':
		this.Pos[loop] = (this.X0 + loop * (this.divwidth+this.Hspace))>this.XMax?this.X0-(this.divwidth+this.Hspace):(this.X0 + loop * (this.divwidth+this.Hspace) + 2);
		this.Top[loop].top = this.Y0;
		this.Top[loop].left = this.Pos[loop] ;
		break;
	case 'Up':
	case 'Down':
		this.Pos[loop] = (this.Y0 + loop * (this.divheight+this.Vspace))>this.YMax?this.Y0-(this.divheight+this.Vspace):(this.Y0 + loop * (this.divheight+this.Vspace) + 2);
		this.Top[loop].top = this.Pos[loop];
		this.Top[loop].left = this.X0 ;
		break;
	default:
		this.Pos[loop] = (this.X0 + loop * (this.divwidth+this.Hspace))>this.XMax?this.X0-(this.divwidth+this.Hspace):(this.X0 + loop * (this.divwidth+this.Hspace) + 2);
		this.Top[loop].top = this.Y0;
		this.Top[loop].left = this.Pos[loop] ;
	}
		
		
	}
}

function Marquee(name){
	this.name = name; //页面元素标识
	this.Pos = new Array();//移动层的左上点位置
	this.X0=0;//显示框的左上点X坐标（相对）
	this.Y0=0;//显示框的左上点Y坐标
	this.XMax=0;//显示框的右下点X坐标
	this.YMax=0;//显示框的右下点Y坐标
	this.Top = new Array();//移动层的位置
	this.scrollerwidth=60;//显示框的宽度
	this.scrollerheight=50;//显示框的高度
	this.divwidth=50;//移动层的宽度
	this.divheight=50;//移动层的高度
	this.Hspace=10;
	this.Vspace=10;
	this.scrollerbgcolor='white';
	this.RollStat = 'Left';//移动方向
	this.RollStep = 3;//移动步长
	//1000 miliseconds=1 seconds
	this.pausebetweenitems=200//移动的间隔时间
	this.slideitems=new Array()	//移动层对象数组
	this.slideitems[0]='Marquee';
	this.slideitems[1]='Demo';
	this.intervalID=0;//间隔ID
	this.ShowMarquee = ShowMarquee;//显示走马灯
	this.StartRoll = StartRoll;//开始滚动
	this.StopRoll = StopRoll;//停止滚动
	this.RollLeft = RollLeft;//左滚
	this.RollRight = RollRight;//右滚
	this.RollUp = RollUp;//上滚
	this.RollDown = RollDown;//下滚
	this.StartRollRight = StartRollRight;//转换成右滚
	this.StartRollLeft = StartRollLeft;//转换成左滚
	this.StartRollUp = StartRollUp;//转换成上滚
	this.StartRollDown = StartRollDown;//转换成下滚
	this.Init = InitPos;
}
