var homeTeaserIndex = 0;
var homeTeaserAutoAnim = true;
var timeoutID;
var lastIndex = 0;
var videourl;

function prevTeaser()
{
	homeTeaserAutoAnim = false;
	homeTeaserIndex--;
	if(homeTeaserIndex < 0)
	homeTeaserIndex = homeTeaser.length-1;
	
	if(homeTeaser.length > 1)
	changeHomeTeaser(homeTeaserIndex, homeTeaserAutoAnim);
}


function nextTeaser(autoAnim)
{
	homeTeaserAutoAnim = autoAnim;
	homeTeaserIndex = homeTeaserIndex + 1;
	if(homeTeaserIndex == homeTeaser.length)
	homeTeaserIndex = 0;
	
	if(homeTeaser.length > 1)
	changeHomeTeaser(homeTeaserIndex, autoAnim);
}


function changeHomeTeaser(currentIndex, autoAnim)
{
	homeTeaserAutoAnim = autoAnim;

	if(!autoAnim)
	clearTimeout(timeoutID);

	var imgContainer = document.getElementById('previewImage');
	var oldSrc = imgContainer.src;

	var newImage = new Image();
	newImage.src = homeTeaser[currentIndex]['img'];
	url = homeTeaser[currentIndex]['url'];


	var anim = fadeOut(imgContainer);
			
	fade = function()
	{
		imgContainer.src = newImage.src;
		fadeIn(imgContainer);
		var homeTeaserInfos = document.getElementById('homeTeaserInfo');
		homeTeaserInfos.getElementsByTagName('h3')[0].innerHTML = homeTeaser[currentIndex]['title'];
		homeTeaserInfos.getElementsByTagName('h4')[0].innerHTML = homeTeaser[currentIndex]['formatTitle'];
		homeTeaserInfos.getElementsByTagName('p')[0].innerHTML = homeTeaser[currentIndex]['text'];

		document.getElementById('previewImageURL').href = homeTeaser[currentIndex]['url'];
	}
	
	document.getElementById('listEntry' + lastIndex).className = 'homeTeaserListEntry';
	document.getElementById('listEntry' + currentIndex).className = 'homeTeaserListEntryActive';	
	lastIndex = currentIndex;

	anim.onComplete.subscribe(fade);
}


function getVideoLink()
{
	window.location.href = url;
}


function fadeOut(div)
{
	var attributes = {
		opacity: { to: 0 }
	};
	var myAnim = new YAHOO.util.Anim(div.id, attributes, 0.2);
	myAnim.animate();
	return myAnim;
}


function debuggah(anyValue){
document.getElementById('debuggah').innerHTML += anyValue;

}

function fadeIn(div)
{
	var attributes = {
		opacity: { to: 1 }
	};
	var myAnim = new YAHOO.util.Anim(div.id, attributes, 0.2);
	myAnim.animate();
	return myAnim; 
}


function changeOpacity(div, opacity, duration)
{
	var attributes = {
		opacity: { to: opacity }
	};
	var myAnim = new YAHOO.util.Anim(div, attributes, duration);
	myAnim.animate();
	return myAnim;
}

function restartTeaserSlideshow(){
	homeTeaserAutoAnim = true;
	initTeaserSlideshow();
	
}
function initTeaserSlideshow()
{
	clearTimeout(timeoutID);
	timeoutID = setTimeout('timeoutEnd()', 5000);
}


function timeoutEnd(){
	nextTeaser(homeTeaserAutoAnim);
	initTeaserSlideshow();
	
}

