newsticker = new function() {
	this.maxTick = newstickerArray.length;
	this.minTick = 1;
	this.maxBound = 10;
	this.currentTick = null;

	this.stop = function() {
		window.clearTimeout(tickTockTimer);
	}

	this.nextTick = function(m) {
		if (m) { this.stop(); }
		if (this.currentTick) {
			if (this.currentTick<this.maxTick) {
				return this.currentTick+1;
			} else {
				return this.maxTick;
			}
		} else {
			return 1;
		}
	}

	this.previousTick = function(m) {
		if (m) { this.stop(); }
		if (this.currentTick) {
			if (this.currentTick>this.minTick) {
				return this.currentTick-1;
			} else {
				return this.minTick;
			}
		}
	}

	this.tickTock = function() {
		newsticker.tickTo(this.nextTick());
		tickTockTimer = window.setTimeout("newsticker.tickTock()",5000);
	}
	this.tickTo = function(n) {
		if (this.currentTick) {
			document.getElementById('button'+this.currentTick).className = 'button'+this.currentTick;
			document.getElementById('text'+this.currentTick).style.display='none';
		}
		document.getElementById('button'+n).className = 'button'+n+'on';
		document.getElementById('text'+n).style.display='block';
		this.currentTick = n;
	}
	this.draw = function() {
		document.write('<ul>');
		document.write('	<li id="header"></li>');
		document.write('	<li id="arrowLeft"><a href="javascript://Föregående nyhet" onclick="newsticker.tickTo(newsticker.previousTick(true));"></a></li>');
		for (var x=this.minTick; x<=this.maxTick; x++)
		{
			document.write('	<li id="button'+x+'" class="button'+x+'"><a href="javascript://'+x+'" onclick="newsticker.tickTo('+x+'); newsticker.stop();"></a></li>');
			document.write('	<li id="text'+x+'" class="text"><a href="'+newstickerArray[x-1][0]+'">'+newstickerArray[x-1][1]+'</a></li>');
		}
		//Lite halvful fix för att visa ut tomma fält till höger om tickern.
		for (var x=(this.maxTick+1); x<=this.maxBound; x++) {
			document.write('	<li class="button'+x+'" style="visibility:hidden;"><a></a></li>');
		}
		document.write('	<li id="arrowRight"><a href="javascript://Nästa nyhet" onclick="newsticker.tickTo(newsticker.nextTick(true));"></a></li>');
		document.write('</ul>');
	}
}


if (newstickerArray) {
	newsticker.draw();
}
if (!newsticker.currentTick)
{
//	newsticker.tickTo(1);
	newsticker.tickTock();
}