﻿function imgfade(){
	var divname = document.getElementById("thepictures"); 	
	var image = divname.getElementsByTagName("li");			
	divname.style.display = "none"; 						
	var NumberOfPics = image.length;						
	NumberOfPics = NumberOfPics-1;   						
	
	// Ändra inställningarna här! 
	
	var WaitTime = 5000;	// Tid att visa bilderna i ms (5000 = 5 sekunder)
	var PicToShow = 0;		// Ställ in den bild som visas först, nr 0 är första
	var FadeSpeed = 70;		// Ställ in hur många millisekunder det ska gå mellan varje uttoningssteg, lägre ger snabbare uttoning.
	var FadeStep = 5;		// Ställ in hur många % som ska tonas ut varje gång, hur ofta det sker ställs in i variabeln ovan.
	var ImgHeight = 150;	// Ställ in hödjden på bilderna, de bör ha samma!
	var ImgWidth = 970;		// Ställ in bredden , kan vara bredare än bilderna, men inte smalare!
	
	// Sluta ändra här!
	
	document.getElementById("slideshowcontainer").style.width = ImgWidth+"px";
	document.getElementById("slideshowcontainer").style.marginBottom = ImgHeight + 20+"px";
	document.getElementById("slideshow").style.zIndex = 1;
	document.getElementById("slideshow").style.position = "absolute";
	document.getElementById("nextpic").style.zIndex = 0;
	document.getElementById("nextpic").style.position = "absolute";
	var divToShowIn= document.getElementById("slideshow");	
	divToShowIn.innerHTML = image[PicToShow].innerHTML;
	var mFadeStep = FadeStep/100;  	
	setTimeout(function() {runFade(divToShowIn,NumberOfPics,PicToShow,image,WaitTime,FadeSpeed,FadeStep,mFadeStep);}, WaitTime);  
}
function runFade(divToShowIn,NumberOfPics,PicToShow,image,WaitTime,FadeSpeed,FadeStep,mFadeStep){
	divToShowIn.style.opacity = 1;
	divToShowIn.style.filter= "alpha(opacity=100)";							
	var PreloadPic=PicToShow+1;
	if (PreloadPic>NumberOfPics){PreloadPic = 0;}  			
	document.getElementById("nextpic").innerHTML = image[PreloadPic].innerHTML;
	var opac = 100;
	fadeout(divToShowIn,opac,FadeSpeed,FadeStep,mFadeStep);									
	divToShowIn.innerHTML = image[PicToShow].innerHTML; 	
	PicToShow = PreloadPic;	
	setTimeout(function() {runFade(divToShowIn,NumberOfPics,PicToShow,image,WaitTime,FadeSpeed,FadeStep,mFadeStep);}, WaitTime);
}

function fadeout(bild,opac,FadeSpeed,FadeStep,mFadeStep){
	if (bild.style.opacity>0){
		bild.style.opacity = bild.style.opacity - mFadeStep;
		opac=opac-FadeStep;
		bild.style.filter= "alpha(opacity=" + opac + ")";
		setTimeout(function() {fadeout(bild,opac,FadeSpeed,FadeStep,mFadeStep);}, FadeSpeed);
	}
}

