/****************************************************************
"bretteleben.de JavaScript Slideshow" - Version 20081101
License: http://www.gnu.org/copyleft/gpl.html
Author: Andreas Berger
Copyright (c) 2008 Andreas Berger - andreas_berger@bretteleben.de
Project page and Demo at http://www.bretteleben.de
Last update: 2008-11-01
*****************************************************************/
//*****erforderliche parameter*****
//array mit den pfaden zu den bildern
//bei nur zwei bildern, diese bitte zweimal angeben ambi_i.e.: 1/2/1/2

// we don't populate the images array because the php-script in head.php did that for us
//aImages =  new Array ('img/head/pic_head_008.jpg', 'img/head/pic_head_009.jpg', 'img/head/pic_head_010.jpg', 'img/head/pic_head_011.jpg', 'img/head/pic_head_015.jpg');

divid = "head_image"; //the id of the div container that will hold the slideshow
picwid = 769; //breite des breitesten bildes in pixel
pichei = 289; //höhe des höchsten bildes in pixel
backgr="#eeeeee"; //hintergrundfarbe der slideshow, falls verschieden grosse oder transparente bilder
//verwendet werden, kann hier z.B. die hintergrundfarbe der seite gesetzt werden
sdur = 20; 		//zeit zwischen den wechseln (überblendung) in sekunden
fdur = 5; 		//dauer des übergangs (überblendung) in sekunden
steps = 50; 	//schritte in denen überblendet wird (je mehr dest sanfter)
startwhen = 1;	// "startwhen" bleibt "null" wenn das script von der seite z.B. per link gestartet wird

//(beispiel: <a href="javascript:myfade();">slide</a>)
// oder wird auf 1 gesetzt, damit das script beim laden der seite automatisch startet
//das wars auch schon, viel spass :)
//mit einem zufälligen bild starten: 
for(ambi_i = 0; ambi_i <= Math.floor(Math.random() * aImages.length); ambi_i++)
{
	aImages.push(aImages.shift());
}
//****************************************************************

ftim = fdur * 1000 / steps;
stim = sdur * 1000;
emax = aImages.length;

// write one div for each image
tp = "<div style='position:absolute;'>";
for (e=1; e <= emax; e++)
{
	theid = "img" + e;
	thesrc = aImages[e-1];
	tp= tp +"<div id='" + theid + "'><img src='" + thesrc + "' border='0'/></div>";
}
tp = tp + "</div>";

// write all style-sheets for all style-divs
document.write("<style type='text/css'>");
for (b=1; b <= emax; b++)
{
	thestylid = "img" + b;
	thez = 1;
	thevis = 'hidden';
	if (b <= 1) 
	{
		thez = 2; 
		thevis = 'visible';
	}
	document.write("#" + thestylid + " {position:absolute;left:0;top:0;width:" + picwid + "px;height:" + pichei + "px;background-color:" + backgr + ";visibility:" + thevis + ";z-index:" + thez + ";}");
}
document.write("</style>");

function myfade()
{
	parr = new Array();
	for (a=1; a <= emax; a++)
	{
		idakt = "img" + a;
		paktidakt = document.getElementById(idakt);
    	ie5exep = new Array(paktidakt);
		parr = parr.concat(ie5exep);}
 		ambi_i = 1;
		ambi_u = 0;
		slide(ambi_i);
	}

function slide(numa)
{
	ptofade = parr[numa-1];
	if (numa <= emax)
	{
		pnext = parr[numa];
	}
	if (numa == emax)
	{
		pnext = parr[0];
	}
	pnext.style.visibility = "visible";
	pnext.style.filter = "Alpha(Opacity=100)";
	pnext.style.MozOpacity = 1;
	pnext.style.opacity = 1;
	ptofade.style.filter = "Alpha(Opacity=100)";
	ptofade.style.MozOpacity = 1;
	ptofade.style.opacity = 1;
	factor = 100 / steps;
	slidenow();
	
}

function slidenow()
{
	check1 = ptofade.style.MozOpacity;
	maxalpha = (100 - factor * ambi_u) / 100 * 105;
	if (check1 <= maxalpha / 100)
	{
		ambi_u++;
	}
	curralpha = 100 - factor * ambi_u;
	ptofade.style.filter = "Alpha(Opacity=" + curralpha + ")";
	ptofade.style.MozOpacity = curralpha / 100;
	ptofade.style.opacity = curralpha / 100;
	if (ambi_u < steps)
	{
		window.setTimeout("slidenow()", ftim);
	}
	if (ambi_u >= steps && ambi_i < emax)
	{
		ptofade.style.visibility = "hidden";
		ptofade.style.zIndex = 2;
		pnext.style.zIndex = 3;		
		ambi_i++;
		ambi_u = 0;
		window.setTimeout("slide(ambi_i)", stim);
	}
	if (ambi_u >= steps && ambi_i >= emax)
	{
		ptofade.style.visibility = "hidden";
		ptofade.style.zIndex = 2;
		pnext.style.zIndex = 3;				
		ambi_i = 1;
		ambi_u = 0;
		window.setTimeout("slide(ambi_i)", stim);
	}		
}

function shownow()
{
	document.getElementById(divid).innerHTML = tp;
	if(startwhen)
	{
		window.setTimeout("myfade()", stim);
	}
}

//onload = shownow;
