/***************************************************
*	JavaScript-Scroll-Funktion	v1.8.0423				*
*	Copyright (c) 2008 by Jörg Schuchardt				*
***************************************************/

function roll_object(obj)
{
//	object
	this.obj = document.getElementById(obj);

	if (!this.obj)	return false;

// handle
	this.handle = obj + "Obj";
	eval(this.handle + " = this;");

// methods
	this.roll = roll;

// variables
	this.roll_tm = false;

//	initialize
	var i = 0;
	while (this.obj.childNodes[i]) {
		if (this.obj.childNodes[i].nodeType != 1) {
			this.obj.removeChild(this.obj.childNodes[i]);
		}
		i++;
	}

	if (!this.obj.childNodes.length) {
		delete this.obj;
		return false;
	}

	return this;
}

function roll(wait, step, dir, msec, auto)
{
	if (!this.obj)	return false;

	if (this.roll_tm)	window.clearTimeout(this.roll_tm);
	this.roll_tm = false;

	if (!wait)	wait = 0;
	if (!step)	step = 1;
	if (!dir)	dir  = false;
	if (!msec)	msec = 25;
	if (!auto) {
		if (step > 0)	this.obj.scrollTop = 0; else
		if (step < 0)	this.obj.scrollTop = this.obj.scrollHeight - this.obj.offsetHeight;

		this.roll_tm = window.setTimeout(this.handle + ".roll(" + wait + ", " + step + ", " + dir + ", " + msec + ", true);", wait);
		return this.roll_tm;
	}

	/* rolling */
	if (step > 0 && this.obj.scrollTop < this.obj.firstChild.offsetHeight + parseInt(this.obj.firstChild.style.marginTop)) {
		this.obj.scrollTop = Math.min(parseInt(this.obj.scrollTop) + step, this.obj.firstChild.offsetHeight + parseInt(this.obj.firstChild.style.marginTop));
		this.roll_tm = window.setTimeout(this.handle + ".roll(" + wait + ", " + step + ", " + dir + ", " + msec + ", true);", msec);
	} else
	if (step < 0 && this.obj.scrollTop > this.obj.scrollHeight - this.obj.offsetHeight - this.obj.lastChild.offsetHeight - parseInt(this.obj.lastChild.style.marginBottom)) {
		this.obj.scrollTop = Math.max(this.obj.scrollHeight - this.obj.offsetHeight - this.obj.lastChild.offsetHeight - parseInt(this.obj.lastChild.style.marginBottom), parseInt(this.obj.scrollTop) + step);
		this.roll_tm = window.setTimeout(this.handle + ".roll(" + wait + ", " + step + ", " + dir + ", " + msec + ", true);", msec);
	}
	// Positionstausch, scrollTop zurücksetzen, Pause
	else {
		if (step > 0) {
			this.obj.appendChild(this.obj.firstChild.cloneNode(true));
			this.obj.removeChild(this.obj.firstChild);
			this.obj.scrollTop = 0;
		} else
		if (step < 0) {
			this.obj.insertBefore(this.obj.lastChild.cloneNode(true), this.obj.firstChild);
			this.obj.removeChild(this.obj.lastChild);
			this.obj.scrollTop = this.obj.scrollHeight - this.obj.offsetHeight;
		}

		this.roll_tm = window.setTimeout(this.handle + ".roll(" + wait + ", " + step + ", " + dir + ", " + msec + ", true);", wait);
	}
	return this.roll_tm;
}

