﻿var aktBild;
var aktBildNr = 0;
var autorun = false;
var objGallerieDiv;
var objImg;
var objPlayButton;
var timeoutID;


function setOpacity(obj, opacity) 
{
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;

  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;

  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}


function slideshowplay(_objGallerieDiv, _objPlayButton)
{
    objGallerieDiv = _objGallerieDiv;
    objImg = _objGallerieDiv.childNodes[0];
    objPlayButton = _objPlayButton;
    
    autorun = true;
    
    objPlayButton.src = '/icons/pause1.jpg';
    objPlayButton.onclick = function() {slideshowpause()}
    
    objPlayButton.alt = 'Pause';
    weiter();
}

function slideshowpause()
{
    autorun = false;
    clearTimeout(timeoutID);
    objPlayButton.src = '/icons/play1.jpg';
    objPlayButton.onclick = function() {slideshowplay(objGallerieDiv, objPlayButton)}
    objPlayButton.alt = 'Starten';
}

function weiter()
{
    if (aktBildNr < bilder.length - 1)
    {
        aktBildNr = aktBildNr + 1;
    }
    else
    {
        return;
    }
        
    //Überlegen, ob man hier nicht einfach gotoBild aufrufen sollte
    objGallerieDiv.style.backgroundImage='url(' + bilder[aktBildNr-1].src + ')';
        
    setOpacity(objImg, 0);
    objImg.src = bilder[aktBildNr].src;
    
    fadeIn(0); 
        
        
    if (autorun)
    {
        timeoutID = setTimeout("weiter()", 5000);
    }
}

		
function fadeIn(opacity)
{
    if (opacity <= 100)
	{
		setOpacity(objImg, opacity);
		opacity += 5;
		setTimeout("fadeIn("+opacity+")", 100);
	}
	else
	{
	    objGallerieDiv.style.backgroundImage='';
	}
}


function gotoBild(_objGallerieDiv, i)
{
    objGallerieDiv = _objGallerieDiv;
    objImg = _objGallerieDiv.childNodes[0];
    
    var altAktBildNr;
    altAktBildNr = aktBildNr;
    
    aktBildNr = i;
    
    objGallerieDiv.style.backgroundImage='url(' + bilder[altAktBildNr].src + ')';
       
    setOpacity(objImg, 0);
    
    objImg.src = bilder[aktBildNr].src;
    document.all.alttext.innerHTML = bilder[aktBildNr].alt;
    
    fadeIn(0); 

    if (autorun)
    {
        timeoutID = setTimeout("weiter()", 5000);
    }

}
