//用于保存定时器上下文对象的容器
var marqueeArray = new Array();

/**
 * marque的构造函数
 */
function Marquee(obj1,obj2){
	//定义对象属性
	this.icefable1 = obj1;
	this.icefable2 = obj2;
	this.marqueesHeight = 18;
	this.stopscroll = false;
	this.preTop = 0;
	this.currentTop = 0;
	this.stoptime = 0;
	
	//定义对象方法
	this.init_srolltext = init_srolltext;
	this.scrollUp = scrollUp;
	this.setTimer = setTimer;
	this.setStopScroll = setStopScroll;
	
	//保存当前引用到一个数组中．为了给哪些不能放到对象中的方法调用
	var index = marqueeArray.length;
	marqueeArray[index] = this;	
	
	//初始化
	this.icefable1.scrollTop = 0;
	with(this.icefable1){
		style.width = 0;
		style.height = this.marqueesHeight;
		style.overflowX = "visible";
		style.overflowY = "hidden";
		noWrap=true;
		onmouseover=new Function("marqueeArray[" + index + "].setStopScroll(true)");
		onmouseout=new Function("marqueeArray[" + index + "].setStopScroll(false)");
	}	
}			
			

/**
 * 初始化函数
 * 定时器居然没有办法调用本对象内的方法.我倒下
 */			
function init_srolltext(){
  this.icefable2.innerHTML = "";
  this.icefable2.innerHTML += this.icefable1.innerHTML;
  this.icefable1.innerHTML = this.icefable2.innerHTML + this.icefable2.innerHTML;
  this.setTimer();
}

/**
 * 设置定时器
 */
function setTimer(){
	//获得最后一个对象，可能有隐患
	var index = marqueeArray.length - 1;
	//marqueeArray[index] = this;
	setInterval("marqueeArray[" + index + "].scrollUp()",50);
}

/**
 * 控制启动停止的标志
 */
function setStopScroll(flag){
	this.stopscroll = flag; 
}

/**
 * 滚动函数
 */
function scrollUp(){
	if(this.stopscroll) return;
	
	this.currentTop += 1;
	if(this.currentTop == 20){
		this.stoptime   += 1;
		this.currentTop -= 1;
		if(this.stoptime == 50){
			this.currentTop = 0;
			this.stoptime = 0;
		}
	}
	else {
		this.preTop = this.icefable1.scrollTop;
		this.icefable1.scrollTop += 1;
		if(this.preTop == this.icefable1.scrollTop){
			this.icefable1.scrollTop = this.icefable2.offsetHeight - this.marqueesHeight;
			this.icefable1.scrollTop += 1;
		}
	}
}	  


