var a;
function CScroller(containerId, contentId, tableId, left_arrow_id, right_arrow_id)
{	
	this.containerId = containerId;
	this.contentId = contentId;
	this.container = document.getElementById(containerId);
	this.content = document.getElementById(contentId);
	this.table = document.getElementById(tableId);
    this.left_arrow = document.getElementById(left_arrow_id);
    this.right_arrow = document.getElementById(right_arrow_id);
    if(this.right_arrow &&  this.left_arrow)
            this.right_arrow.style.display = this.left_arrow.style.display ="none";
    this.speed = 1;
	this.x = this.content.style.left = 0;
	this.dx = 0;
	this.endX = 0;
	this.maxX = this.table.offsetWidth - this.container.offsetWidth;
    if(this.maxX < 0)
        this.maxX = 0;
    this.timerId = 0;
		
	this.onLoad = CScroller_onLoad;
	this.moveTo = CScroller_moveTo;
	this.startScroll = CScroller_startScroll;
	this.scroll = CScroller_scroll;
	this.stopScroll = CScroller_stopScroll;
	this.doubleSpeed = CScroller_doubleSpeed;
	this.resetSpeed = CScroller_resetSpeed;
	this.onLoad();
	a = this;
	return this;
}

function CScroller_onLoad()
{	
	//TODO: move to the index of the current picture
    if(this.maxX > 0)
    {
        if(this.right_arrow &&  this.left_arrow)
            this.right_arrow.style.display ="block";
    }
    this.ready = true;
	this.content.style.visibility="visible";
}
function CScroller_moveTo(new_x)
{
	this.content.style.left=(this.x=new_x)+"px";
    if(this.maxX >0)
    {
        if(this.dx == 1)
        {
            this.right_arrow.style.display = "block";
        }
        else
        {
            this.left_arrow.style.display = "block";
        }
        if(this.x == this.endX)
        {
            if(this.dx == 1)
            {
                this.left_arrow.style.display = "none";
            }
            else
            {
                this.right_arrow.style.display = "none";
            }
            this.resetSpeed();
        }
    }
}
function CScroller_startScroll(direction)
{
	if (!this.ready)
		return;
	if(direction == "left")
	{
		this.dx = 1;
		this.endX = 0;
	}
	else
	{
		this.dx = -1;
		this.endX =  -this.maxX;
	}
	
	if (this.timerId) 
		clearInterval(this.timerId);
	a = this;
	this.timerId = setInterval( "a.scroll()", 10);
}
function CScroller_scroll()
{
	var new_x = this.x + (this.dx * this.speed * 2) ;	
	if ( ( this.dx == -1 && new_x > -this.maxX ) || ( this.dx == 1 && new_x < 0 ) ) 
	{
		this.moveTo(new_x);	
	} 
	else
	{
		clearInterval(this.timerId); 
		this.timerId = 0;
		this.moveTo(this.endX);
	}
}
function CScroller_stopScroll()
{
	if (!this.ready) return;
	if (this.timerId) 
	  clearInterval(this.timerId);
	this.timerId = 0;  
	//this.conent = null;
}
function CScroller_doubleSpeed()
{
	this.speed = 2;
}

function CScroller_resetSpeed()
{
	this.speed = 1;
}

  

