var homeTeaserIndex = 0;
var homeTeaserAutoAnim = true;
var homeTeaserTimeoutID;

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, homeTeaserAutoAnim);
}


function changeHomeTeaser(currentIndex, autoAnim)
{
	if(!autoAnim)
	clearTimeout(homeTeaserTimeoutID);

	var imgContainer = document.getElementById('preview');
	var oldSrc = imgContainer.src;
	
	var newImage = new Image();
	newImage.src = homeTeaser[currentIndex]['img'];
	
	var anim = fadeOut(imgContainer);
	
	fade = function()
	{
		imgContainer.src = newImage.src;
		fadeIn(imgContainer);
		document.getElementById('teaser_big_home_headline').innerHTML 		= homeTeaser[currentIndex]['headline'];
		document.getElementById('teaser_big_home_subheadline').innerHTML 	= homeTeaser[currentIndex]['text'];
		document.getElementById('teaser_big_home_url').href 			= homeTeaser[currentIndex]['url'];
                if(homeTeaser[currentIndex]['target'])
                document.getElementById('teaser_big_home_url').target 			= homeTeaser[currentIndex]['target'];
	}
	anim.onComplete.subscribe(fade);
}


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.25);
	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(homeTeaserTimeoutID);
	homeTeaserTimeoutID = setTimeout('timeoutEnd()', 7000);
}

function timeoutEnd(){
	nextTeaser(homeTeaserAutoAnim);
	initTeaserSlideshow();
}

