function Scroller(imgWidth, id)
{
	this.imgWidth = imgWidth;
	this.el = YAHOO.util.Dom.get(id);
	YAHOO.util.Event.addListener(window, "resize", function(e, scroller) {scroller.show();}, this);
	if (document.all)
	{
	    YAHOO.util.Event.addListener(window, "load", function(e, scroller) {scroller.show();}, this);
	}
	else
	{
        YAHOO.util.Event.onAvailable(id, function(scroller) {scroller.show();}, this);
	}
	this.pos = 0;
}

Scroller.cellWidth = 125;

Scroller.prototype.show = function()
{
    var region = YAHOO.util.Dom.getRegion(this.el);
    var width = region.right - region.left - this.imgWidth;
    this.nrOfCells = Math.floor(width / Scroller.cellWidth) - 1;
	var cells = this.el.getElementsByTagName("td");
	this.max = cells.length;
	
    if (this.pos > this.max - this.nrOfCells)
    {
        this.pos = this.max - this.nrOfCells;
    }
    if (this.pos < 0)
    {
        this.pos = 0;
    }
	
	if (this.pos > 0)
	{
		for(var i = 0; i < this.pos; i++)
		{
            YAHOO.util.Dom.replaceClass(cells[i], "show", "hidden");
		}
	}
	for (var i = this.pos; i < this.max; i++)
	{
		width = width - Scroller.cellWidth;
		if (width < Scroller.cellWidth)
		{
			YAHOO.util.Dom.replaceClass(cells[i], "show", "hidden");
		}
		else
		{
            YAHOO.util.Dom.replaceClass(cells[i], "hidden", "show");
		}
	}
};

Scroller.prototype.right = function()
{
    this.pos++;
    this.show();
    Timer.start(this, "right", 600);
};

Scroller.prototype.left = function()
{
    this.pos--;
    this.show();
    Timer.start(this, "left", 600);
};

Scroller.prototype.fastRight = function()
{
    this.pos ++;
    this.show();
    Timer.start(this, "fastRight", 200);
};

Scroller.prototype.fastLeft = function()
{
    this.pos --;
    this.show();
    Timer.start(this, "fastLeft", 200);
};

Scroller.prototype.end = function()
{
    this.pos = this.max;
    this.show();
};

Scroller.prototype.start = function()
{
    this.pos = 0;
    this.show();
};

Scroller.stop = function()
{
    Timer.stop();
};


function Timer(){}

Timer.start = function(scroller, dir, speed)
{
	Timer.scroller = scroller;
	Timer.dir = dir;
	Timer.timer = setTimeout("Timer.move()", speed);
};

Timer.move = function()
{
	switch(Timer.dir)
	{
        case "left": Timer.scroller.left(); break;
        case "right": Timer.scroller.right(); break;
        case "fastRight": Timer.scroller.fastRight(); break;
        case "fastLeft": Timer.scroller.fastLeft(); break;
	}
};

Timer.stop = function()
{
    if (Timer.timer) clearTimeout(Timer.timer);
    Timer.scroller = null;
};