
function hideAndShowItem(i, value) {
	//var cont = document.getElementById(id);
	var img = String("newsImage_" + i);
	var txt = String("newsText_" + i);
	
	if(value == true) {
		// Item anzeigen
		changeOpac(0, img, txt);
		document.getElementById(img).style.display = "block";
		document.getElementById(txt).style.display = "block";
		opacity(img, txt, 0, 100, 500);
	} else {
		// Item ausblenden
		opacity(img, txt, 100, 0, 500);
		setTimeout(function() {
			changeOpac(0, img, txt);
			document.getElementById(img).style.display = "none";
			document.getElementById(txt).style.display = "none";
							}, 500);
	}
}

function nextNews() {
	clearTimeout(timeoutManager);
	var nextItem = activeItem + 1;
	if(nextItem >= allItems) {
		nextItem = 0;
	}

	hideAndShowItem(activeItem, false);
	setTimeout(function() {
		hideAndShowItem(nextItem, true);
		timeoutManager = setTimeout(nextNews, timeoutTime);
		activeItem = nextItem;
	}, 500);
	
}

function prevNews() {
	clearTimeout(timeoutManager);
	var prevItem = activeItem - 1;
	if(prevItem < 0) {
		prevItem = allItems-1;
	}
	
	hideAndShowItem(activeItem, false);
	setTimeout(function() {
		hideAndShowItem(prevItem, true);
		timeoutManager = setTimeout(nextNews, timeoutTime);
		activeItem = prevItem;
	}, 500);
	
}

function opacity(id, id2, 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 + "','" + id2 + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "','" + id2 + "')",(timer * speed));
			timer++;
		}
	}
}

function changeOpac(opacity, obj1, obj2) {
	var object = document.getElementById(obj1).style;
	
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
	
	var object2 = document.getElementById(obj2).style;
	
	object2.opacity = (opacity / 100);
	object2.MozOpacity = (opacity / 100);
	object2.KhtmlOpacity = (opacity / 100);
	object2.filter = "alpha(opacity=" + opacity + ")";
}
