function newstickerClass() {}

/**
 * @var	Die Richtung in die sich die news bewegt.
 * 		1 => rechts nach links
 * 		2 => links nach rechts
 * 		3 => unten nach oben
 * 		4 => oben nach unten
 * 		5 => keine Animation
 */
newstickerClass.prototype.direction = -1;

/**
 * @var	Die Dauer um die News um einen Pixel zu bewegen.
 */
newstickerClass.prototype.moveSpeed = -1;

/**
 * @var	Gibt an ob die News gerade nicht weiter läuft.
 */
newstickerClass.prototype.pause = false;


/**
 * @var	Die Id des Newstickers.
 */
newstickerClass.prototype.id = -1;

/**
 * @var	Der Divtag in dem die News sind.
 */
newstickerClass.prototype.div = -1;

/**
 * @var	Die Zeilenhöhe des Textes. Wird nur bei Richtung 3 und 4 benötigt.
 */
newstickerClass.prototype.lineHeight = -1;

/**
 * @var	Die Größe des sichtbaren Bereichs.
 */
newstickerClass.prototype.visible = -1;

/**
 * @var	Der maximale Scrollwert.
 */
newstickerClass.prototype.max = -1;

newstickerClass.prototype.move = function () {
	if (!this.pause) {
		if (this.getPosition() < this.max) {
			this.setPosition(this.getPosition() + 1);
		} else {
			this.setPosition(0);
		}
	}
	setTimeout('newsticker' + this.id + '.move()', this.moveSpeed);
}

newstickerClass.prototype.getPosition = function () {
	switch (this.direction) {
		case 1:
			return this.div.scrollLeft;
		case 2:
			return this.max - this.div.scrollLeft;
		case 3:
			return this.div.scrollTop;
		case 4:
			return this.max - this.div.scrollTop;
	}
	return void(0);
}

newstickerClass.prototype.setPosition = function (position) {
	switch (this.direction) {
		case 1:
			this.div.scrollLeft = position;
			break;
		case 2:
			this.div.scrollLeft = this.max - position;
			break;
		case 3:
			this.div.scrollTop = position;
			break;
		case 4:
			this.div.scrollTop = this.max - position;
			break;
	}
}

newstickerClass.prototype.__construct = function (id, direction, speed) {
	this.id = id;
	this.div = document.getElementById('newsticker' + this.id);

	this.div.onmouseover = function () {
		self['newsticker' + id].pause = true;
	}
	this.div.onmouseout = function () {
		self['newsticker' + id].pause = false;
	}

	this.direction = direction;
	this.moveSpeed = speed / 300;

	if (window.opera) {
		this.div.style.overflow = 'auto';
	}

	switch (this.direction) {
		case 1: case 2:
			if (this.div.offsetWidth == 0) {
				setTimeout('newsticker' + this.id + '.__construct(' + id + ', ' + direction + ', ' + speed + ')', this.moveSpeed);
				return false;
			}

			if (parseInt(this.div.style.height.substr(0, this.div.style.height.length - 2)) > parseInt(this.div.style.lineHeight.substr(0, this.div.style.lineHeight.length - 2))) {
				this.div.style.lineHeight = this.div.style.height;
			}

			var span = document.createElement('span');
			span.style.paddingRight = this.div.style.width;
			this.div.insertBefore(span, this.div.firstChild);
			this.div.appendChild(span.cloneNode(false));

			if (window.opera) {
				this.div.style.lineHeight = Number(this.div.style.lineHeight.substr(0, this.div.style.lineHeight.length - 2)) - 1 + 'px';
				this.div.style.height = Number(this.div.style.height.substr(0, this.div.style.height.length - 2)) + 15 + 'px';
			}
			this.visible = this.div.offsetWidth;
			this.max = this.div.scrollWidth - this.visible;
			break;
		case 3: case 4:
			if (this.div.offsetHeight == 0) {
				setTimeout('newsticker' + this.id + '.__construct(' + id + ', ' + direction + ', ' + speed + ')', this.moveSpeed);
				return false;
			}

			var div = document.createElement('div');
			div.style.height = this.div.style.height;
			this.div.insertBefore(div, this.div.firstChild);
			this.div.appendChild(div.cloneNode(false));

			this.lineHeight = this.div.style.lineHeight.substr(0, 2);
			this.visible = this.div.offsetHeight;
			this.max = this.div.scrollHeight - this.visible;
			break;
		case 5:
			this.div.style.overflow = 'auto';
			break;
	}
	switch (this.direction) {
		case 2: case 4:
			this.setPosition(0);
			break;
	}

	setTimeout('newsticker' + this.id + '.move()', this.moveSpeed);
	return true;
}				
