// Change Teaser Page
var currentPage = 0;
var maxPages = 0;

function changePage(nr, type) {
	nr = parseInt(nr, type);
	if(nr <= maxPages) {
		goToPage(nr, type);
	}
}

function goToPage(nr, type) {

	// jetzige Raus
	opacity(type + "_navigation", 100, 0, 100);
	opacity(type + "_page_" + currentPage, 100, 0, 1000);
	changeOpac(0, type + "_page_" + nr);
	
	setTimeout(function() {
		document.getElementById(type + "_navigation").innerHTML = "&nbsp;";
		document.getElementById(type + "_page_" + currentPage).style.display = "none";
		document.getElementById(type + "_page_" + nr).style.display = "block";
		opacity(type + "_page_" + nr, 0, 100, 1000);
		currentPage = nr;
		setTimeout(function() {
			checkPagination(nr,type);
		}, 1050);
	}, 1050);
}

function checkPagination(nr, type) {
	var newTextLinks = "";
	if(nr > 0) {
		newTextLinks += "<a href=\"javascript:void(0);\" onclick=\"changePage("+(nr-1)+", '"+type+"')\">&lt;site " + currentPage + "</a>";
	}
	
	if(nr > 0 && nr < maxPages) {
		newTextLinks += "&nbsp;";	
	}
	
	if(nr < maxPages) {
		newTextLinks += "<a href=\"javascript:void(0);\" onclick=\"changePage("+(nr+1)+", '"+type+"')\">site " + (currentPage+2) + "&gt;</a>";
	}
	document.getElementById(type + "_navigation").innerHTML = newTextLinks;
	opacity(type + "_navigation", 0, 100, 100);
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}