// JS-Klasse für den Aufbau von Newstickern
// Programmiert von Lukas Klement Feb. 2003

function newsticker(name,content,posX,posY,width,height,bgColor,orientation,direction,stepInterval,stepSize,padding,noStop)
{
	// Attribute
	this.name=name;
	this.content=content;
	this.posX=posX;
	this.posY=posY;
	this.width=width;
	this.height=height;
	this.orientation=(orientation?orientation:"H");
	this.padding=(padding?padding:0);
	this.direction=(direction?direction:1);
	this.stepSize=(stepSize?stepSize:2);
	this.bgColor=bgColor;
	this.currentStatus=1;
	this.noStop=noStop;

	// Methoden 
	this.build=newsticker_build;
	this.position=newsticker_position;
	this.move=newsticker_move;
	this.status=newsticker_status;

	// Aufbau des Tickers
	this.build();
	if (this.layerObj)
	{
		// Setzen der Werte für Grundposition
		if (this.orientation=="H")
		{
			this.currentPosY=0;
			if (this.direction==1) {this.currentPosX=0-this.width;}
			if (this.direction==-1) {this.currentPosX=this.totalWidth;}
		}
		if (this.orientation=="V")
		{
			this.currentPosX=0;
			if (this.direction==1) {this.currentPosY=0-this.height;}
			if (this.direction==-1) {this.currentPosY=this.totalHeight;}
		}
		// Herstellen der Grundposition
		this.position(this.currentPosX,this.currentPosY);
		// Sichtbarmachen des Tickers
		if (document.getElementById)
		{
			document.getElementById("ticker"+this.name+"2").style.visibility="visible";
		}
		else
		{
			this.layerObj.visibility="visible";
		}
		// Ticker starten
		this.interval=window.setInterval(this.name+".move()",(stepInterval?stepInterval:30));
	}
}

// Methode zur Scroll-Unterbrechung 
function newsticker_status(status)
{
	if (this.noStop || status) {this.currentStatus=1;} else {this.currentStatus=0;}
}

// Bewegen des Newstickers
function newsticker_position(x,y)
{
	// Gespeicherte Position aktualisieren
	this.currentPosX=x;
	this.currentPosY=y;
	// Beim Erreichen des Endes Koordinaten für Umpositionieren setzen
	if (this.orientation=="H")
	{
		if (this.direction==1 && this.currentPosX>this.totalWidth) {this.currentPosX=0-this.width;}
		if (this.direction==-1 && this.currentPosX<-this.width) {this.currentPosX=this.totalWidth;}
	}
	if (this.orientation=="V")
	{
		if (this.direction==1 && this.currentPosY>this.totalHeight) {this.currentPosY=0-this.height;}
		if (this.direction==-1 && this.currentPosY<-this.height) {this.currentPosY=this.totalHeight;}
	}
	// Layer versetzen
	this.layerObj.left=-this.currentPosX;
	this.layerObj.top=-this.currentPosY;
	// Speziell für NS6 - unterbinden des Scrollbars
	if (document.getElementById)
	{
		this.layerObj.maxWidth=this.currentPosX+this.width;
		this.layerObj.maxHeight=this.currentPosY+this.height;
		this.layerObj.overflow="hidden";
	}
}

// Funktion für die Newstickerbewegung (Intervallfunktion)
function newsticker_move()
{
	var x=0;
	var y=0;
	// neue Koordinate ermitteln
	if (this.orientation=="H") {x=this.currentPosX+(this.direction*this.stepSize*this.currentStatus);}
	if (this.orientation=="V") {y=this.currentPosY+(this.direction*this.stepSize*this.currentStatus);}
	// Layerbewegung iniitiieren
	this.position(x,y);
}

// Methode für den Aufbau des Newstickers
function newsticker_build()
{
	// Content in Tabelle "einpacken"
	if (this.orientation=="H") {var content="<table id=ticker"+this.name+"cell border=0 cellspacing=0 cellpadding="+this.padding+"><tr><td nowrap height="+this.height+"><nobr>"+this.content+"</nobr></td></tr></table>";}
	else {var content="<table id=ticker"+this.name+"cell border=0 cellspacing=0 cellpadding="+this.padding+"><tr><td width="+this.width+">"+this.content+"</td></tr></table>";}

	// Aufbau DOM-Browser (IE5+, NS6+, Konqueror2+, Opera 5+)
	if (document.getElementById)
	{
		document.getElementById('myContent').innerHTML += "<div id='ticker"+this.name+"1' onmouseout='"+this.name+".status(true);' onmouseover='"+this.name+".status(false);' style='position:absolute;"+(this.bgColor?"background-color:"+this.bgColor+";":"")+"left:"+this.posX+"px;top:"+this.posY+"px;width:"+this.width+"px;height:"+this.height+"px;overflow:hidden;'><div id='ticker"+this.name+"2' visibility=hidden style='position:absolute;left:-2000px;top:-2000px;'>"+content+"</div></div>";

		this.layerObj=document.getElementById("ticker"+this.name+"2").style;
		this.totalWidth=document.getElementById("ticker"+this.name+"cell").offsetWidth;
		this.totalHeight=document.getElementById("ticker"+this.name+"cell").offsetHeight;
	}
	// Aufbau Netscape 4.x
	if (document.layers)
	{
		document.getElementById('myContent').innerHTML += "<layer onmouseout='"+this.name+".status(true);' onmouseover='"+this.name+".status(false);' name=ticker"+this.name+"1 id=ticker"+this.name+"1 "+(this.bgColor?"bgColor='"+this.bgColor+"'":"")+" left="+this.posX+" top="+this.posY+" width="+this.width+" height="+this.height+" clip='0, 0, "+this.width+", "+this.height+"'><layer visibility=hide name=ticker"+this.name+"2 id=ticker"+this.name+"2>"+content+"</layer></layer>";
		this.layerObj=document.layers["ticker"+this.name+"1"].document.layers["ticker"+this.name+"2"];
		this.totalWidth=this.layerObj.clip.right;
		this.totalHeight=this.layerObj.clip.bottom;
	}
}