function Scroller(target, speed, width, btnP, btnN, step) {
	this.index = 0;

	this.el = document.getElementById(target);
	if (!this.el) return;
	this.el.style.left = '2000px';
	this.btnPrevious = document.getElementById(btnP);
	this.btnNext = document.getElementById(btnN);

  // store button state images
  /*
  this.btnNextEnabled = this.btnNext.getElementsByTagName('img')[0].src;
  var parts = this.btnNextEnabled.split(".gif");
  this.btnNextDisabled = parts[0] + "2.gif";

  this.btnPreviousEnabled = this.btnPrevious.getElementsByTagName('img')[0].src;
  parts = this.btnPreviousEnabled.split(".gif");
  this.btnPreviousDisabled = parts[0] + "2.gif";
*/
  var o = this;
	if (this.btnPrevious) 
//    this.btnPrevious.onclick = function() { o.previousItem(); this.blur(); return false; }
	if (this.btnNext) 
//    this.btnNext.onclick = function() { o.nextItem(); this.blur(); return false; }
	this.itemWidth = width;
	this.continuous = true;
	this.items = this.getItems();
	this.itemCount = this.items.length;
	this.step = (step == null) ? 1 : step;
}

Scroller.prototype.getItems = function() {
	var items = new Array();
	var o = this;
	var childNodes = child_nodes(this.el);
	for (var i=0; i<childNodes.length; i++) {
		var child = childNodes[i];
		if(child.nodeName == 'A' && child.hasChildNodes()) {
			child.onmouseclick = function() { this.blur(); }
			child.onmouseover = function() {
				var img = this.getElementsByTagName('img')[0];
				img.style.marginLeft = "-610px";
			}
			child.onmouseout = function() {
				var img = this.getElementsByTagName('img')[0];
				img.style.marginLeft = "0px";
			}
		}
		items.push(child);
	}
	return items;
}

Scroller.prototype.setItem = function(i) {
	if (this.itemCount <= this.step) {
		this.moveItem(0);
		this.disableButton(this.btnPrevious);
		this.disableButton(this.btnNext);
		return;
	}
	this.index = (this.continuous) ? i+1 : i;
	if (!this.continuous && this.index == 0) this.disableButton(this.btnPrevious);
	this.moveItem(this.index);
}

Scroller.prototype.setRandomItem = function() {
	this.index = Math.round(Math.random()*(this.itemCount-1));
	this.moveItem(this.index);
}

Scroller.prototype.enableButton = function(btn) {
  return;
  var img = btn.getElementsByTagName('img')[0];
  if (img.src.indexOf("left") > 0)
    img.src = this.btnPreviousEnabled;
  else
    img.src = this.btnNextEnabled;
  return;
  var parts = img.src.split("2.gif");
  // hack...
  if (parts.length == 2)
    img.src = parts[0] + ".gif";
}

Scroller.prototype.disableButton = function(btn) {
  return;
	var img = btn.getElementsByTagName('img')[0];
  if (img.src.indexOf("left") > 0)
    img.src = this.btnPreviousDisabled;
  else
    img.src = this.btnNextDisabled;
  return;
  
  var img = btn.getElementsByTagName('img')[0];
  img.src = this.btnPreviousDisabled;
  return;
  var parts = img.src.split(".gif");
  if (parts.length == 2)
    img.src = parts[0] + "2.gif";
}

Scroller.prototype.nextItem = function() {

  var newIndex = this.index + this.step;

  if (!this.continuous)
    {
    // threre are only 2 items the step is more than the number of items
    if ( (this.itemCount < 2) || (newIndex >= this.items.length) )
      return;
    // enable if we are past the first step
    if (newIndex >= this.step)
      this.enableButton(this.btnPrevious);
    if (newIndex >= (this.items.length-this.step))
      this.disableButton(this.btnNext);
    }
  this.index += this.step;
  if (this.index == this.items.length)
      {
      this.moveItem(0);
      this.index = 1;
      }
  this.displayItem();
}

Scroller.prototype.previousItem = function() {
  var newIndex = this.index - this.step;
  if (!this.continuous)
    {
    if (this.itemCount < 2 || newIndex < 0)
      return;
    if (newIndex == 0)
      this.disableButton(this.btnPrevious);
    if (newIndex < (this.items.length - this.step))
      this.enableButton(this.btnNext);
    }

	this.index -= this.step;
	if (this.index == -1) {
		this.moveItem(this.itemCount-1);
		this.index = this.itemCount-2;
  	}
	this.displayItem();
}

Scroller.prototype.moveItem = function(i) {
	this.el.style.left = -(this.itemWidth*i) + 'px';
}

Scroller.prototype.displayItem = function() {
	this.tweenItem(-this.itemWidth*(this.index));
}

Scroller.prototype.tweenItem = function(end) {
	var elScroll = new fx.ElementScroll(this.el, {duration: 600, transition: fx.sinoidal});
	elScroll.tween(end);
}