var iAktuelleSeite = 1;
var infosProSeite = 4;
var maxSeiten = 3;
var activeID = 1;
var incativeID = null;
var tableID = "aktuelles";
var aAktuellesCollection = new Array();

var animinterval = null;

/* printPageNav()
 * 
 */
function printPageNav(){
	var pageNav = document.getElementById("pageNav");
	var nav = document.createElement('dl');
	
	var dt = document.createElement('dt');
	dt.innerHTML = 'Seite ';
	nav.appendChild(dt);
	for(var i = 1; i <= maxSeiten; i++){
		dd = printListPoint(i);
		nav.appendChild(dd);
	}

	pageNav.appendChild(nav);
	setPageActive(activeID);
}

function printListPoint(i){
	var dd = document.createElement('dd');

	var anchor = document.createElement('a');
	anchor.innerHTML = i;
	anchor.setAttribute("title", "Seite " + i);
	anchor.onclick = function(event) { gotoPage(i); stopToggle(); };
	anchor.setAttribute("id", "pageID" + i);
	anchor.href = '#' + tableID;

	dd.appendChild(anchor);
	return dd;
}


/* gotoPage()
 * 
 */
function gotoPage(pageID){

	if(pageID > maxSeiten)
		pageID == 1;

	var startIndex = (pageID == 1) ? 0 : infosProSeite * (pageID - 1);
	var ende = startIndex + infosProSeite;

	clearBox();
	setPageActive(pageID);
	fillBox(startIndex, ende);
	tableID.focus;
}

function clearBox(){
	var box = document.getElementById(tableID);

	while(box.childNodes.length > 0)
		box.removeChild(box.firstChild);

}

function fillBox(startIndex, ende){
	var box = document.getElementById(tableID);

	for(var i = startIndex; i < ende; i++) {
		listpoint = aAktuellesCollection[i].toHTML();
		box.appendChild(listpoint);
	}
	return box;
}


/* toggle()
 * 
*/
function toggle(){
	iAktuelleSeite++;
	
	if(iAktuelleSeite > maxSeiten)
			iAktuelleSeite  = 1; 
	
	gotoPage(iAktuelleSeite);
}

function startToggle(){

	if(animinterval != null)
		stopToggle();

	animinterval = setInterval("toggle()",10000);

}
function stopToggle(){

	if(animinterval != null)
		clearInterval(animinterval);
	animinterval = null;
}


/* active / inactive 
 * 
 */
function setPageActive(pageID){

	if(typeof(inactiveID) != "undefined")
		setPageInactive(inactiveID);

	var page = document.getElementById("pageID" + pageID);
	page.style.backgroundColor = "#B40002";
	page.style.color = "#fff";
	
	inactiveID = pageID;
}

function setPageInactive(inactiveID){
	var inactivePage = document.getElementById("pageID" + inactiveID);
	inactivePage.style.backgroundColor = "#fff";
	inactivePage.style.color = "#B40002";
}


/* class Aktuelles
 * 
 */
function cAktuelles(icon, text, url) {
	this.icon = icon;
	this.text = text;
	this.url = url;
	
	this.toHTML = function() {
		li = document.createElement("li");
		li.className = this.icon;
		li.innerHTML = '<a href="' + this.url + '">' + this.text + '</a>';
		
		return li;
	}
}
