var aTracking = new Array()

var marquee = function ( parent_id, pic_id, scrollType, speed, height ){
	this.Speed = speed ;
	this.scrollType = scrollType ;
	this.parent_id = parent_id;
	this.pic_id = pic_id;
	this.height = height;
	this.parent = document.getElementById(this.parent_id);
	this.pic = document.getElementById(this.pic_id);
	this.init();
	
	this.parent.parent_id = this.parent_id;
	this.parent.pic_id = this.pic_id;
	this.parent.scrollType = this.scrollType;
	this.parent.Speed = this.Speed;
	this.parent.time_id = setInterval( "moving('"+this.parent_id+"','"+this.pic_id+"','"+this.scrollType+"')",this.Speed);
	this.parent.onmouseout = function() {
		this.time_id = setInterval( "moving('"+this.parent_id+"','"+this.pic_id+"','"+this.scrollType+"')", this.Speed);
	}
	this.parent.onmouseover = function (){
		clearInterval(this.time_id );
	}
	
}
marquee.prototype.init = function (){
		var height = this.height;
		var parent= document.getElementById(this.parent_id);
		var pic = document.getElementById(this.pic_id);
		//alert(this.height);
		
		if(height && height!=null) {
			parent.style.height = '100%';
			if(parent.offsetHeight<100) 
				parent.style.height = height + 'px';
		}else this.setHeight(parent,pic);
		
		if(this.scrollType=='h')	{
			this.setHeight(parent,pic);
			pic.style.whiteSpace='nowrap';
			pic.style.left = !pic.style.left ? '0px':pic.style.left;
		}else if(this.scrollType=='v'){
			//this.setWidth (this.parent,this.pic);			
			pic.style.top = !pic.style.top ? '0px':pic.style.top;
		}
}


function moving(parent_id,pic_id,scrollType){
		var parent = document.getElementById(parent_id);
		var pic = document.getElementById(pic_id);
		if(scrollType=='h'){
			if(-1*parseInt(pic.style.left) >= pic.offsetWidth) pic.style.left = parent.offsetWidth+'px';
			else pic.style.left = parseInt(pic.style.left)-1 + 'px';
		}else if(scrollType=='v'){
			if(-1*parseInt(pic.style.top) >= pic.offsetHeight ) pic.style.top = parent.offsetHeight+'px';
			else pic.style.top = parseInt(pic.style.top)-1 + 'px';
		}
		//window.status = "pic-offset :"+pic.offsetHeight + ","+pic.style.top + "    parent-offset:"+parent.offsetWidth + ","+parent.offsetHeight;
}

marquee.prototype.setHeight = function (parent,pic) {
		if(!parent.style.height||parent.style.height == null||parent.style.height=='undefined')
			parent.style.height = pic.offsetHeight + 'px';
}

marquee.prototype.setWidth = function (parent,pic) {
		if(!parent.style.width ||parent.style.width  == null||parent.style.width =='undefined')
			parent.style.width = pic.offsetWidth + 'px';
}
