Scroller = function (object) {
	this.scrollerObject		= object;
	this.name				= "Scroller1";
	this.lineHeight			= 22;
	this.scrollSpeed		= 4000;

	this.moveSpeed			= 10;
	this.state				= "";
	this.moveTimer;				
	this.autoMoveTimer;			
	this.beforMovePixels	= 0;
	this.autoScrollFlag	= false

	clearInterval(this.moveTimer);
	clearInterval(this.autoMoveTimer);

	return this;
}

Scroller.prototype.setName = function(this_name)			{ this.name = this_name }
Scroller.prototype.setLineHeight = function(line_height)	{ this.lineHeight = line_height; }
Scroller.prototype.setScrollSpeed = function(scroll_speed)	{ this.ScrollSpeed = scroll_speed; }

Scroller.prototype.setAutoScroll = function(auto_scroll_flag) {
	if(auto_scroll_flag) {
		this.autoScrollFlag = true;
	} else {
		this.autoScrollFlag = false;
	}

	this.autoScroll(this.autoScrollFlag);
}

Scroller.prototype.movePrev = function() {

	this.state = "MOVE_PREV";
	this.moveTimer = setInterval(this.name+ ".runScroll(-1)", this.moveSpeed);
}

Scroller.prototype.moveNext = function(pixels) {

	this.state = "MOVE_NEXT";
	this.moveTimer = setInterval(this.name+ ".runScroll(1)", this.moveSpeed);
}

Scroller.prototype.runScroll = function(move_pixels) {
	if(this.state == "") return;

	if(this.beforMovePixels >= this.lineHeight) {
		clearInterval(this.moveTimer);

		this.state = "";
		this.beforMovePixels = 0;

		this.autoScroll(this.autoScrollFlag);

	} else {
		// next
		if(	move_pixels > 0 && this.scrollerObject.scrollTop == (this.scrollerObject.scrollHeight - this.lineHeight)) {
			this.beforMovePixels = this.lineHeight;
			this.scrollerObject.scrollTop = 0;
			return;
		}

		// prev
		if(	move_pixels < 0 && this.scrollerObject.scrollTop == 0) {
			this.beforMovePixels = this.lineHeight;
			this.scrollerObject.scrollTop = (this.scrollerObject.scrollHeight - this.lineHeight);
			return;
		}

		this.scrollerObject.scrollTop = this.scrollerObject.scrollTop + move_pixels;
		this.beforMovePixels++;
	}
}

Scroller.prototype.autoScroll = function(flag) {
	if(flag) {
		clearInterval(this.autoMoveTimer);
		this.autoMoveTimer = setInterval(this.name+ ".runAutoScroll()", this.scrollSpeed);
	} else {
		clearInterval(this.autoMoveTimer);
	}
}

Scroller.prototype.runAutoScroll = function() {
	this.state = "AUTO_SCROLL";
	this.moveTimer = setInterval(this.name+ ".runScroll(1)", this.moveSpeed);
}
