BT.ns(function() {with(BT) {
	Slideousel = Class.create({
		initialize: function(containerId, options) {
			this.setOptions(options);
			
			this.currentIndex = 0;
			this.liSize = 0;
			this.animDone = true;
			
			this.containerId = containerId;

			this.updateCount();
			
			this.buttonLeft = $(this.options.leftId);
			this.buttonRight = $(this.options.rightId)
		
			this.buttonLeft.observe('click', this.moveLeft.bindAsEventListener(this));
			this.buttonRight.observe('click', this.moveRight.bindAsEventListener(this));
			
			this.moveLeft(); // force the left button to start disabled
		},
		
		updateCount: function() {
			this.ul = $$('#' + this.containerId + ' ul')[0];
			this.listCount = this.ul.getElementsByTagName("li").length;
			
			if(this.listCount < this.options.numVisible) {
				this.options.numVisible = this.listCount;
			}
		},
		
		moveRight: function() {

			if (this.animDone != true) 
				return false;
			
			if (this.currentIndex + this.options.numVisible + this.options.increment <= this.listCount)
				this._scroll(-this.options.increment);
			else 
				this._scroll(-(this.listCount - (this.currentIndex + this.options.numVisible)));
			
			if(this.listCount == this.currentIndex + this.options.numVisible)
				Element.addClassName(this.buttonRight, this.options.disabledClass);
			
			Element.removeClassName(this.buttonLeft, this.options.disabledClass);
		},
		
		moveLeft: function() {
			if (this.animDone != true)
	      		return false;
			
		    var inc = this.options.increment;
	
		    if (this.currentIndex - inc < 0)
				inc = this.currentIndex;
		    
		    this._scroll(inc);
		    
		    if (this.currentIndex == 0)
				Element.addClassName(this.buttonLeft, this.options.disabledClass);
				
			if(this.listCount > this.options.numVisible)
			    Element.removeClassName(this.buttonRight, this.options.disabledClass);
			else
				Element.addClassName(this.buttonRight, this.options.disabledClass);
		    
		},
		
		allRight: function() {
			if (this.animDone != true)
	      		return false;
		
	      	var inc = this.listCount - this.currentIndex - this.options.numVisible;
			this._scroll(-inc);
			
			Element.addClassName(this.buttonRight, this.options.disabledClass);
			Element.removeClassName(this.buttonLeft, this.options.disabledClass);
		},
		
		allLeft: function() {
			if (this.animDone != true)
	      		return false;
		
			this._scroll(this.currentIndex);
			
			Element.addClassName(this.buttonLeft, this.options.disabledClass);
		    Element.removeClassName(this.buttonRight, this.options.disabledClass);
		},
		
		_scroll: function(delta) { 
 
		    this.animDone = false;
		    
		    if(this.liSize <= 0) 
				this.liSize = this._getLiElementSize();

		    new Effect.MoveBy(this.ul, 0, delta * this.liSize, {duration: 0.3, afterFinish: function() {this.animDone = true}.bind(this)});

		    this.currentIndex -= delta;
	
	  	},
	  	
	  	_getLiElementSize: function() {
			var li = $(this.ul.getElementsByTagName("li")[0]);
			return li.getDimensions().width + parseFloat(li.getStyle("margin-left")) + parseFloat(li.getStyle("margin-right"));
  		},
  	
		setOptions: function (options) {
			this.options = {
				numVisible: 4,
	      		increment: 1,
	      		leftId: 'slide_left',
	      		rightId: 'slide_right',
	      		disabledClass: 'slide_disabled'
			};
			Object.extend(this.options, options || {});
		}
	});
}});