﻿var images=new Array();

	images[0]="one_on";
	images[1]="two_on";
	images[2]="three_on";

var arrayLength=images.length;

var active=Math.floor(Math.random()*arrayLength);

var k=1;

var fadeinTimer,fadeoutTimer,hideTimer;

function reset()
{
	document.getElementById("Leistung1").className="one_off";
	document.getElementById("Leistung2").className="two_off";
	document.getElementById("Leistung3").className="three_off";
}
	
function animate(c,d)
{
	clearTimeout(fadeinTimer);
	clearTimeout(fadeoutTimer);
	clearTimeout(hideTimer);
	
	if(d=="first")
	{
		fadeIn(c);
		active=c;
		k=active;
		timerID=setInterval("autorotator()",7000)
	}
	
	if(d==true)
	{
		timerID=clearInterval(timerID)
	}
	
	reset();
	
	if(active!=c)
	{
		fadeOut(active);
		fadeIn(c);
		active=c
	}
	
	document.getElementById("Leistung"+(c+1)).className=images[c];
	
	if(d==true)
	{
		k=active;
		timerID=setInterval("autorotator()",7000)
	}
}

function autorotator()
{
	animate(k,false);
	
	if(k!=(arrayLength-1))
	{
		k=k+1
	}else
	{
		k=0
	}
}

function getElm(b)
{
	return document.getElementById(b)
}

function show(b)
{
	getElm(b).style.display="block"
}

function hide(b)
{
	getElm(b).style.display="none"
}

function setOpacity(d,f)
{
	var e=getElm(d).style;
	e.opacity=f/100;
	e.filter="alpha(opacity="+f+")"
}

function fadeIn(e)
{
	setOpacity(e,0);
	show(e);
	var f=0;
	for(var d=1;d<=100;d++)
	{
		fadeinTimer=setTimeout("setOpacity('"+e+"',"+d+")",f*5);
		f++
	}
}

function fadeOut(e)
{
	var f=0;
	for(var d=100;d>=1;d--)
	{
		fadeoutTimer=setTimeout("setOpacity('"+e+"',"+d+")",f*3);
		f++
	}

	hideTimer=setTimeout("hide('"+e+"')",500)
}


