initSlideshow();

function initSlideshow()
{
	var images = ss_images;
	var images_alt = ss_imagesalt;
	var images_links = ss_imageslinks;
	var stime = ss_showpictime * 1000;
	var ftime = ss_fadetime * 1000/steps;
	
	var steps = 20;
	var slide = 0;
	var starttime = 1;
	var step = 0;
	var pictureArr = new Array();
  
  	this.createContent = function()
	{
   		var content = "<div class='pictures'>";
		
		for(i=1; i <= images.length; i++)
		{
			display = 'none';
			if(i <= 1) 
			{ 
				display = 'block';
			}
			
			content += "<div class='picture' id='picture-" + i + "' style='display:" + display + ";'>";
			imageTag = "<img src='" + images[(i-1)] + "' style='' alt='" + images_alt[(i-1)] + "'/>";
			
			if(images_links[(i-1)] != undefined)
			{
				content += "<a href='" + images_links[(i-1)] + "' title='" + images_alt[(i-1)] + "'>" + imageTag + "</a>";
			}
			else
			{
				content += imageTag;
			}
			
			content += "</div>";
		}
   		
   		content += "</div>";
   			
		document.getElementById('slideshow').innerHTML = content;
		this.buildImagesArr();
	}
  
	this.buildImagesArr = function()
	{
		for(i=1; i <= images.length; i++)
		{
			elem = document.getElementById("picture-" + i);
    		pictureArr = pictureArr.concat(new Array(elem));
    	}

		slide = 1;
		setTimeout(
			function()
			{
				this.preparePicture();
			},
			stime
		);
	}

	this.preparePicture = function()
	{
		step = 0;
		actPicture = pictureArr[starttime-1];
		
		if(starttime < images.length)
		{
			nextPicture = pictureArr[starttime];
		}
		else
		{
			nextPicture = pictureArr[0];
		}
		
		nextPicture.style.zIndex = 1;
		nextPicture.style.display = "block";
		nextPicture.style.filter = "Alpha(Opacity=100)";
		nextPicture.style.MozOpacity = 1;
		nextPicture.style.opacity = 1;
		
		actPicture.style.zIndex = 2;
		actPicture.style.display = "block";
		actPicture.style.filter = "Alpha(Opacity=100)";
		actPicture.style.MozOpacity = 1;
		actPicture.style.opacity = 1;
		
		factor = 100/steps;
		
		if(slide == 1)
		{
			this.slidePicture();
		}
	}

	this.slidePicture = function()
	{	
		actOpacity = actPicture.style.opacity;
			
		if(actOpacity <= 1)
		{
			step++;
		}
		
		// set current opacity
		curralpha = 100 - factor * step;
		actPicture.style.filter="Alpha(Opacity=" + curralpha + ")";
		actPicture.style.MozOpacity = curralpha / 100;
		actPicture.style.opacity = curralpha / 100;
		
		if(step < steps)
		{
			if(slide == 1)
			{
				setTimeout(
					function()
					{
						this.slidePicture();
					},
					ftime
				);
			}
			else 
			{
				this.preparePicture();
			}
		}
		else
		{
			actPicture.style.zIndex = 1;
			nextPicture.style.zIndex = 2;
		
			if(starttime < images.length)
			{
				actPicture.style.display = "none";
				starttime++;
			}
			else
			{
				actPicture.style.display = "block";
				starttime=1;
			}
			
			step = 0;
			
			setTimeout(
				function()
				{
					this.preparePicture();
				},
				stime
			);
		}
	}

	this.startSlideshow(this.createContent);
}

function startSlideshow(func){
	window.onload = function(){
		func();
	};
}
