
function autoscroll (opt) {
	if(!opt) 
		var opt  = {};
	var _this    = this;
	_this._speed = opt.speed;
	_this._t     = null;
	_this.old    = -1;
	_this.cur    = -1;
	_this.count  = opt.count;

	_this.btns   = opt.btns;
	_this.btnpre = opt.pre;
	_this.btnext = opt.next;

	_this.running = false;
	
	_this.go = null;

	_this.stop = function() {
		clearInterval(_this._t);
	};

	_this.start = function() {
		_this.scroll();
	};

	_this.index = function(i) {
		if(_this.cur == i)
			return(false);
		_this.old = _this.cur;
		_this.cur = i;
		_this.stop();
		_this.go(i);
	}
	_this.pre = function() {
		if(_this.cur <= 0 || _this.count <= 1)
			return(false);
		else {
			_this.stop();
			_this.old = _this.cur;
			_this.cur--;
			_this.go(_this.cur);
		}
	};
	_this.next = function() {
		if(_this.cur + 1 >= _this.count)
			return(false);
		else {
			_this.stop();
			_this.old = _this.cur;
			_this.cur++;
			_this.go(_this.cur);
		}
	};

	if(_this.btns) {
		_this.btns.hover(function() {
			_this.stop();
		}, function() {
			_this.start();
		});
	}

	if(_this.btnpre && _this.btnext) {
		_this.btnpre.hover(function() {
			_this.stop();
		}, function() {
			_this.start();
		});

		_this.btnext.hover(function() {
			_this.stop();
		}, function() {
			_this.start();
		});
	}

	_this.scroll = function() {
		_this._t = setInterval(function() {

			_this.stop();
			if(_this.cur + 1 >= _this.count) {
				_this.old = _this.cur;
				_this.cur = 0;
				_this.go(0);
			} else {
				_this.old = _this.cur;
				_this.cur++;
				_this.go(_this.cur);
			}
			_this.start();

		}, _this._speed);
	}
}
