var nextBigPic=new Image();

function switchBigPic(path)
{	
	// Falls der Fade-Vorgang noch in aktion ist, abbrechen
	if(opacitiyProgress["bigPic"]) return;

	var bufferPic=new Image();
	bufferPic.src=path+".jpg";

	// Falls es das gleiche Bild ist, abbrechen
	if(bufferPic.src==document.getElementById("bigPic").src) return;
	
	nextBigPic.src=bufferPic.src;	
	nextBigPic.onload=function()
	{
		document.getElementById("photo").style.backgroundImage="url("+nextBigPic.src+")"; 
		fadeOut("bigPic", 1);
	}
}

function openSelector()
{
	document.getElementById('selection').style.height='auto';
	document.getElementById('firstEntry').style.display='none';
}

function closeSelector()
{
	document.getElementById('selection').style.height='17px';
	document.getElementById('firstEntry').style.display='block';
}


// Fade-Funktionen

// Parameter festlegen
var fadeInTimer=new Array();
var fadeOutTimer=new Array();
var opacitiyProgress=new Array();
var opacitiyAvailable=true;
var opacity=0;
var opacityFull=1;
var fadeEnd=0;
var opacityZero=0;
var fadeInStep=0.05;
var fadeOutStep=0.05;
var stepTime=20;


function fadeIn(id, opacity)
{
	if(!opacitiyAvailable) return;
	
	clearTimeout(fadeOutTimer[id]);
	
	opacity=opacity+fadeInStep;
	opacitiyProgress[id]=opacity;
	
	setOpacitiy(id, opacity);
	
	if(opacity+fadeInStep<opacityFull) fadeInTimer[id]=setTimeout("fadeIn('"+id+"', "+opacitiyProgress[id]+")", stepTime);
	else 
	{
		setOpacitiy(id, opacityFull);
		opacitiyProgress[id]=opacityFull;

		nextBigPic.src=document.getElementById('bigPic').src;
	}
}

function fadeOut(id, opacity)
{	
	if(!opacitiyAvailable) return;
	
	clearTimeout(fadeInTimer[id]);
	
	opacity=opacity-fadeOutStep;
	opacitiyProgress[id]=opacity;
	
	setOpacitiy(id, opacity);
	
	if(opacity-fadeOutStep>fadeEnd) fadeOutTimer[id]=setTimeout("fadeOut('"+id+"', "+opacitiyProgress[id]+")", stepTime);
	else
	{
		setOpacitiy(id, fadeEnd);
		opacitiyProgress[id]=fadeEnd;

		document.getElementById('bigPic').src=nextBigPic.src;
	}
}

function getFadeOpacity(id)
{	
	if(!opacitiyAvailable) return;

	// ueberpruefen ob Tranparenz unterstuetzt wird
	if(document.getElementById(id).style.filter=="undefined" && document.getElementById(id).style.opacity=="undefined")
	{
		opacitiyAvailable=false;
		return;
	}
	else
	{
		if(opacitiyProgress[id]) return opacitiyProgress[id];
		else return 0;
	}	
}

function setOpacitiy(id, opacity)
{
	if(document.all) document.getElementById(id).style.filter="Alpha(opacity="+opacity*100+")";
	else document.getElementById(id).style.opacity=opacity;
}