// JavaScript Document
var MoveScroller = function(selector){
	return this instanceof MoveScroller ? 
		this.init(selector) : 
		new MoveScroller(selector);
}
MoveScroller.prototype = {
	intervalID : 0,
	init : function (selector){
		this.options = {
			speed : 10,			
			eName : selector
		};
	},
	find : function (id){
		return document.getElementById(id);
	},
	left : function () {
		var refScroller = this;
		if(this.intervalID ==0)
			this.intervalID = window.setInterval(function (){refScroller.move("left");},refScroller.options.speed);
	},
	right : function (){
		var refScroller = this;
		if(this.intervalID ==0)
			this.intervalID = window.setInterval(function (){refScroller.move("right");},refScroller.options.speed);
		//alert(this.intervalID);
	},
	move : function (ty){
		var obj = this.find(this.options.eName);
		if(obj.style.left === '')
			obj.style.left = 0;
	
		var left = parseInt(obj.style.left.toString());
		var width = obj.offsetLeft+obj.offsetWidth;
		if(ty == 'right'){
			if(Math.abs(left-10) > width){
				obj.style.left = (-width)+"px";
				window.clearInterval(this.intervalID);
				this.intervalID = 0;
                return;
			}
			else{
				obj.style.left = (left - 10)+"px";
			}
		}
		else if(ty == 'left')
			obj.style.left = (left >= 0 ? 0 : (left+10))+"px";
		
		if(parseInt(obj.style.left)%530==0){
			window.clearInterval(this.intervalID);
			this.intervalID = 0;
			return;			
		}
	}
};
var test1 = MoveScroller('list1');
var test2 = MoveScroller('list2');