	/*create by G5
	email:it@g58.net
	最后修改：2009-4-10
	*/

	/*图像或图层滚动类，带暂停效果，可上下左右滚动，兼容多浏览器
	参数说明：
	tagId - 字串 - 主容器标签ID,向竖向滚动时，其CSS的HEIGHT属性值应该小于容器内容高度值，向横向滚动时，其CSS的WIDTH值应该小于容器内容宽度值，CSS一定要设:overflow:hidden属性
	tagContentId - 字串 - 主容器标签的内容放置标签ID，用于放置滚动内容，其CSS的高度或宽度值应该根据滚动方向大于主容器的相应值，要设置对象属性noWrap为true(横向滚动时需要）
	copyTagId - 字串 - 用于放置主容器内容副本的标签ID，存放主容器标签原始内容，并计算原内容真实高度或宽度值，该标签要设为隐藏
	scrollLength - 数值- 滚动的长度值，以px为单位
	stepTime - 数值 - 滚动时的速度，以ms为单位
	stayTime - 数值 - 滚动指定长度值后暂停的时间，以ms为单位
	direction - 字串 - 滚动方向，可以设为"up","down","left","right"四个方向
	callerName - 字串 - 类构造出的对象名称，用于定时器正确调用创建对象的滚动函数
	
	*/
	function scrollEx(tagId,tagContentId,copyTagId,scrollLength,stepTime,stayTime,direction,callerName){
		this.stopFlag=false;
		this.preScrollPlace=0;
		this.currentScrollCount=0;
		this.stayTimeCount=0;
		this.scrollAmount=0;
		this.direction=direction;
		
		this.init=function(){
			$(tagId).style.overflow="hidden";
			$(tagContentId).noWrap=true;
			$(copyTagId).innerHTML=$(tagContentId).innerHTML;
			$(tagContentId).innerHTML+=$(copyTagId).innerHTML;
			$(copyTagId).style.position="absolute";
			$(copyTagId).style.left="-9999px";
			$(copyTagId).style.zIndex="1";
			$(copyTagId).style.visibility="hidden";
			
			this.scrollAmount=scrollLength;
			if((this.direction=="up"||this.direction=="down") && ($(tagId).offsetHeight > $(copyTagId).offsetHeight)){
				$(tagContentId).innerHTML=$(copyTagId).innerHTML;
				return;
			}
			if((this.direction=="left"||this.direction=="right") && ($(tagId).offsetWidth > $(copyTagId).offsetWidth)){
				$(tagContentId).innerHTML=$(copyTagId).innerHTML;
				return;
			}
			switch(this.direction){
				case "left":
					$(tagContentId).style.width=$(copyTagId).offsetWidth * 2+"px";
					$(tagContentId).style.height=$(tagId).offsetHeight+"px";
					$(tagId).scrollTop=0;
					$(tagId).scrollLeft=0;
					break;
				case "right":
					$(tagContentId).style.width=$(copyTagId).offsetWidth * 2+"px";
					$(tagContentId).style.height=$(tagId).offsetHeight+"px";
					$(tagId).scrollTop=0;
					$(tagId).scrollLeft=$(copyTagId).offsetWidth;
					break;
				case "up":
					$(tagContentId).style.width=$(tagId).offsetWidth+"px";
					$(tagContentId).style.height=$(copyTagId).offsetHeight * 2+"px";
					$(tagId).scrollTop=0;
					$(tagId).scrollLeft=0;
					break;
				case "down":
					$(tagContentId).style.width=$(tagId).offsetWidth+"px";
					$(tagContentId).style.height=$(copyTagId).offsetHeight * 2+"px";
					$(tagId).scrollTop=$(copyTagId).offsetHeight;
					$(tagId).scrollLeft=0;
					break;
			}
			$(tagId).onmouseover=new Function(callerName+".stopFlag=true");
			$(tagId).onmouseout=new Function(callerName+".stopFlag=false");
			setInterval(callerName+".play()",stepTime);
		}
		this.play=function(){
			if(this.stopFlag)return;	
			this.currentScrollCount++;
			if(this.currentScrollCount>this.scrollAmount){
				this.stayTimeCount++;
				this.currentScrollCount--;
				if(this.stayTimeCount==stayTime/stepTime+1){
					this.currentScrollCount=0;
					this.stayTimeCount=0;
				}
			}else{
				this.scrollProcess();
			}
		}
		this.scrollProcess=function(){
			switch(this.direction){
				case "left":
					this.preScrollPlace=$(tagId).scrollLeft;	
					$(tagId).scrollLeft+=1;	
					if(this.preScrollPlace==$(tagId).scrollLeft){	
						$(tagId).scrollLeft=$(copyTagId).offsetWidth-$(tagId).offsetWidth;	//重置滚动条的左边位置，换到第一份内容的最后位置左边界
						$(tagId).scrollLeft+=1;	//继续滚动
					}
					break;	
				case "right":
					this.preScrollPlace=$(tagId).scrollLeft;
					$(tagId).scrollLeft-=1;
					if(this.preScrollPlace==0){
						$(tagId).scrollLeft=$(copyTagId).offsetWidth;
						$(tagId).scrollLeft-=1;
					}
					break;	
				case "up":
					this.preScrollPlace=$(tagId).scrollTop;
					$(tagId).scrollTop+=1;
					if(this.preScrollPlace==$(tagId).scrollTop){
						$(tagId).scrollTop=$(copyTagId).offsetHeight-$(tagId).offsetHeight;
						$(tagId).scrollTop+=1;
					}
					break;	
				case "down":
					this.preScrollPlace=$(tagId).scrollTop;
					$(tagId).scrollTop-=1;
					if(this.preScrollPlace==0){
						$(tagId).scrollTop=$(copyTagId).offsetHeight;
						$(tagId).scrollTop-=1;
					}
					break;	
			}
		}
		function $(tagId){
			return document.getElementById(tagId)?document.getElementById(tagId):null;
		}
	}


