var listSlider = Fx.Scroll.extend({
	moreOptions: function () {
		return {
			nextButton: 'rightButton',
			prevButton: 'leftButton',
			startAt: 0, // Start at li number #
			startAtID: false, // Start a specific li with give id
			scrollBy: 2, // How many li's to scroll
			vertical: false, // Vertical or horizontal ?
			buttonHandler: Class.empty
		}
	},
	initialize: function (element, options) {
		this.setOptions(this.moreOptions(), options);
		this.parent(element,this.options);
		// TODO: Vertical Selber
		this.size = this.element.getSize();
		this.bound = [true,true];
		this._init();
	},
	_init: function () {
		this.container = this.element.getElementsByTagName('li');
		offset = (this.options.vertical ? 'offsetHeight' : 'offsetWidth');
		this.scrollVal = this.container[1][offset];
		this.timeout = null;
		if (this.options.startAtID) {
			for (i=0;i<this.container.length;i++)
				if (this.options.startAtID == this.container[i].id) {
					this.options.startAt = i+1;
					break;
				}
		}
		this.buttons = [this.options.prevButton, this.options.nextButton];
		$(this.buttons[1]).addEvent('mousedown', this.next.bind(this, false));
		$(this.buttons[0]).addEvent('mousedown', this.prev.bind(this, false));
		document.addEvent('mouseup', this._clear.bind(this, false));
		this.current = (this.container.length-this.visible);
		this.visible = Math.round(this.element[offset]/this.scrollVal);
		this._scroll(this.options.startAt-1, true);
	},
	_scroll: function (val, useEl) {
		// FIXME
		if (this.current == (this.container.length-this.visible))
			this.buttonHandler(1, true);
		else if (this.current == 0)
			this.buttonHandler(0, true);
			
		if (val > (this.container.length-this.visible)) val = (this.container.length-this.visible);
		if (isNaN(val)|| val < 0) val = 0; 
		this.current = val;
		
		if (useEl) this.element.scrollTo(this.container[val].offsetLeft, this.container[val].offsetTop);
		else {
			//this.options.myEffect.start(;
			this.scrollTo(this.container[val].offsetLeft, this.container[val].offsetTop);
		}
		ret = true;
		//$('hider').innerHTML = this.container.length + '-'+this.visible+'|'+this.options.startAt+':'+this.scrollVal + ':' + this.current + ';'+ this.container[this.current].id;
		if (this.current >= (this.container.length-this.visible)) {
			this.buttonHandler(1, false);
			this._clear();
			ret = false;
		}
		if (this.current == 0) {
			this.buttonHandler(0, false);
			this._clear();
			ret = false;
		}
		return ret;
	},
	next: function () {
		if (this._scroll(this.current + this.options.scrollBy))
			this.timeout = window.setTimeout(this.next.bind(this, false), 500);
	},
	prev: function () {
		if (this._scroll(this.current - this.options.scrollBy))
			this.timeout = window.setTimeout(this.prev.bind(this, false), 500);
	},
	buttonHandler: function (button, val) {
		if (val) {
			if (button == 1 && !this.bound[1])
				$(this.buttons[1]).addEvent('mousedown', this.next.bind(this, false));
			else if (button == 0 && !this.bound[0])
				$(this.buttons[0]).addEvent('mousedown', this.prev.bind(this, false));
		}
		else {
			$(this.buttons[button]).removeEvents();
			this.bound[button] = false;
		}
		if (this.options.buttonHandler) this.options.buttonHandler(this.buttons[button], val);
	},
	_clear: function () {
		if (this.timeout) $clear(this.timeout);
	},
	destroy: function () {
		$(this.buttons[1]).removeEvents();
		$(this.buttons[0]).removeEvents();
		document.removeEvents();
	}
});