var aSlide = new Array(nPics);
var aPic = new Array(nPics);
var nPicsUBound = nPics - 1;
var nView;
var oAuto;
var sFlipFlopFunct = "auto";
var bFlipFlopAlight = false;
var sURLParam;
var aURLParam;
var nFirstPic = 0;
var n;

var bAutoOff = false;
if (bAutoOff == null) bAutoOff = true;

sURLParam = document.location.search;
sURLParam = sURLParam.substr(1,sURLParam.length - 1);
aURLParam = sURLParam.split("&");
if (! isNaN(parseInt(aURLParam[0])))
{
	if (parseInt(aURLParam[0]) < nPics) nFirstPic = parseInt(aURLParam[0]);
}

for (n = 0; n < nPics; n++)
{
	aSlide[n] = new Image();
	aSlide[n].src = aSlidePicSrc[n][0];
}

function Pic(n)
{
	if (aPic[n] == null)
	{
		aPic[n] = new Image();
		aPic[n].src = aSlidePicSrc[n][1];
	}
}	

function NextPic(n)
{	
	if (n < nPicsUBound && aPic[n + 1] == null)
	{
		aPic[n + 1] = new Image();
		aPic[n + 1].src = aSlidePicSrc[n + 1][1];
	}
} 
	
function LoadBtn(sName, sState)
{
	eval("document." + sName).src = "images/fotogalerie/btn_" + sName + sState + ".gif";
}

function LoadFlipFlop(sFunct, bAlight)
{
	var sState = (bAlight) ? "Al" : "";
	document.auto_stop.src = "images/fotogalerie/btn_" + sFunct + sState + ".gif";
}

function SetFocus(nPic)
{
	if (document.getElementById)
	{
		for (n = 0; n < nPics; n++)
		{
			if (n == nPic) 
			{
				document.getElementById("PaddingTop" + n).style.height="3px";
				document.getElementById("i" + n).style.border="4px solid #CD4819";
				document.getElementById("PaddingBot" + n).style.height="3px";
			}
			else
			{
				document.getElementById("PaddingTop" + n).style.height="6px";
				document.getElementById("i" + n).style.border="1px solid #777777";
				document.getElementById("PaddingBot" + n).style.height="6px";
			}
		}
	}
}

function ShowPic(n)
{
	SetFocus(n);
	Pic(n);

	if (n == 0) 
	{
		LoadBtn("back", "Da");
		LoadBtn("first", "Da");
	}
	else
	{
		LoadBtn("back", "");
		LoadBtn("first", "");
	}
	
	if (n == nPicsUBound)
	{
		LoadBtn("forw", "Da");
		LoadBtn("last", "Da");
	}
	else
	{
		LoadBtn("forw", "");
		LoadBtn("last", "");
	}

	nView = n;
	document.frm.num.value = "Foto " + (n + 1) + " von " + nPics;       

	if (document.main.filters) document.main.filters.revealTrans.Apply();
	document.main.src = aPic[n].src;
	if (document.main.filters) document.main.filters.revealTrans.Play();  
	document.frm.legend.value = aText[n];
	if (document.getElementById) document.getElementById("main").style.border="0 solid #777777";
}

function Back()
{
	if (0 < nView) 
		ShowPic(nView - 1); 
}

function Forw()
{
	if (nView < nPicsUBound) 
		ShowPic(nView + 1);
}

function Up()
{
	if (nView > 0) 
		ShowPic(0);
}

function Down()
{
	if (nView < nPicsUBound) 
		ShowPic(nPicsUBound);
}

function Stop()
{ 
	window.clearTimeout(oAuto);
	sFlipFlopFunct = "auto";
	ChangeCursor();
	LoadFlipFlop(sFlipFlopFunct, bFlipFlopAlight);	
}

function Auto()
{ 
	if (bAutoOff && nView == nPicsUBound - 1)					
	{								
		sFlipFlopFunct = "auto";
		ChangeCursor();					
		LoadFlipFlop(sFlipFlopFunct, bFlipFlopAlight);		
		Forw();							
		window.clearTimeout(oAuto);
	}
	else
	{
		if (sFlipFlopFunct == "auto")
		{
			sFlipFlopFunct = "stop";
			ChangeCursor();
			LoadFlipFlop(sFlipFlopFunct, bFlipFlopAlight);
		}
		if (nView == nPicsUBound) Up();
		else Forw();
		oAuto = window.setTimeout("Auto();", 5000);
	}
}

function AutoStop()
{
	if (sFlipFlopFunct == "auto") Auto();
	else Stop();
}

function Halt()
{ 
	window.clearTimeout(oAuto);
	if (sFlipFlopFunct == "stop") 
	{
		sFlipFlopFunct = "auto";
		ChangeCursor();
		LoadFlipFlop(sFlipFlopFunct, bFlipFlopAlight);
	}
}

function ChangeCursor()
{
	if (document.getElementById)
	{
		if (sFlipFlopFunct == "stop") document.getElementById("main").style.cursor = "pointer";
		else document.getElementById("main").style.cursor = "default";
	}
}
