/************************************************************************


	Autor:		Patrick Seiler
	Copyright:	2006, nextmarket GmbH
	Verison:	1.0


************************************************************************/


function vScrollText(left, top, width, height, HTML, speed, time, name, id) {
	this.left = left;
	this.top = top;
	this.width = width;
	this.height = height;
	this.HTML = HTML;
	this.speed = speed;
	this.name = name;
	this.time = time;
	this.id = id;
	
	this.numBoxes = function() {
		var container = document.createElement('div');
		container.style.top = String(this.top) + 'px';
		container.style.left = String(this.left) + 'px';
		container.style.width = String(this.width) + 'px';
		container.style.visibility = 'hidden';
		container.innerHTML = this.HTML;
		
		//document.getElementsByTagName("body")[0].appendChild(container);
		document.getElementById(this.id).appendChild(container);
	    
		this.scrollHeight = container.scrollHeight;
		var count = Math.ceil(this.height / container.scrollHeight);
		
		if (count <= 1) {
			count = 2;
		} else count = count + 1;
		
		//document.getElementsByTagName("body")[0].removeChild(container);
		document.getElementById(this.id).removeChild(container);

		delete container;
		return count;
	}
	
	this.vscroll_init = function () {
		this.boxes = this.numBoxes();
		this.divArray = new Array(this.boxes);
		
		for (i=0; i < this.boxes; i++) {
			this.divArray[i] = document.createElement('div');
			this.divArray[i].style.position = 'absolute';
			this.divArray[i].style.top = this.top + (i * this.scrollHeight) + this.height + 'px';
			this.divArray[i].style.left = this.left + 'px';
			this.divArray[i].style.width = this.width + 'px';
			this.divArray[i].style.visibility = 'visible';
			this.divArray[i].style.zIndex = 200;
			this.divArray[i].id = 'box' + String(i);
			this.divArray[i].innerHTML = this.HTML;
			
			//document.getElementsByTagName("body")[0].appendChild(this.divArray[i]);
			document.getElementById(this.id).appendChild(this.divArray[i]);
		}
	}
	
	this.vscroll = function () {	

		for (i=0; i < this.boxes; i++) {
			
			// Alle Boxen um this.vscroll nach ober verschieben
			this.divArray[i].style.top = parseInt(this.divArray[i].style.top.slice(0,-2)) - this.speed + 'px';
			
			if (parseInt(this.divArray[i].style.top.slice(0,-2)) + this.scrollHeight < this.top + this.speed) {
				this.divArray[i].style.top = this.top + (this.boxes - 1) * this.scrollHeight + 'px';
			}
			
			// Prüfen welche Box sichtbar ist
			if (parseInt(this.divArray[i].style.top.slice(0,-2)) <= (this.top + this.height) && parseInt(this.divArray[i].style.top.slice(0,-2)) + this.scrollHeight >= this.top) {
				this.divArray[i].style.visibility = 'visible';
				clipTop = this.top - parseInt(this.divArray[i].style.top.slice(0,-2));
				if (clipTop < 0) {
					clipTop = '0px';
				} else clipTop = clipTop + 'px';
				
				clipBottom = this.top + this.height - parseInt(this.divArray[i].style.top.slice(0,-2)) + 'px';
				clipWidth = this.width +'px';
	
				this.divArray[i].style.clip = 'rect('+clipTop+', '+clipWidth+', '+clipBottom+', 0px)';
			} else this.divArray[i].style.visibility = 'hidden';
		}
		this.start();
	}
	
	this.start = function () {
		window.setTimeout(this.name + ".vscroll()", this.time);
	}
	
	this.vscroll_init();
	this.start();
}