// JavaScript Document

function Roller(id,name){
	this.name = name;
	this.id = document.getElementById(id);
	this.elem = this.id.getElementsByTagName('div');//new Array();
	this.count = this.elem.length;
	this.margin = 5;
	this.offset = 0;
	this.pos = new Array();
	this.auto;
	this.speed = 2;
	
	this.init = function(){
		var temp;
		var temp2;
		if(this.count > 0)
		for(var i=0; i<this.count;i++)
		{
			if(undefined === this.pos[i])
				this.pos[i] = i;
			temp = this.pos[i]*(this.elem[i].offsetWidth+this.margin);
			temp2 = temp+this.offset;
			/*
			if( temp2 < (-1*temp))
				temp2 = temp2+(this.elem[i].offsetWidth+this.margin)*this.count;
			*/
			this.elem[i].style.left = temp2+'px';
		}
	},
	
	this.Play = function(){
		if(this.count > 0)
		this.auto = setInterval(this.name+'.next()', 50);
	},
	
	this.Stop = function(){
		clearInterval(this.auto);
	},
	
	this.next = function(){ 
		
		this.offset -= this.speed;
		
		if(this.offset+this.elem[0].offsetWidth+this.margin <= 0)
		{
			this.offset = 0;
			this.repos();
		}
		
		this.init();
	},
	
	this.repos = function()
	{
		for( var i=0 ; i<this.count ; i++)
		{
			this.pos[i] -= 1;
			if(this.pos[i]<0)
				this.pos[i] = this.count-1;
		}
	}
}
