var slideshow_timer_1 = null;
var slideshow_timer_2 = null;
var slideshow_status  = "stopped";
var previous_item_nr = 1;

function opacity(id, opacStart, opacEnd, millisec)
{
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//determine the direction for the blending, if start and end are the same nothing happens
	/*if(millisec == 0)
	{
		pasOpacityAan(1, id);
	}
	else*/
	
	
		if(opacStart > opacEnd) 
		{
			for(i = opacStart; i >= opacEnd; i--)
			{
				setTimeout("pasOpacityAan(" + i + ",'" + id + "');", (timer * speed));
				timer++;
			}
		} 
		else if(opacStart < opacEnd)
		{
			for(i = opacStart; i <= opacEnd; i++)
			{
				setTimeout("pasOpacityAan(" + i + ",'" + id + "');", (timer * speed));
				timer++;
			}
		}
	
}

//change the opacity for different browsers
function pasOpacityAan(opacity, id) 
{
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}	

function previousSlideshowItem()
{
	clearTimeout(slideshow_timer_1);
	clearTimeout(slideshow_timer_2);
	
	(document.getElementById("slideshow_image_" + previous_item_nr)).style.visibility = "hidden";
	opacity("slideshow_image_" + previous_item_nr, 100, 0, 0);

	item_nr -= 2;

	toonItemDirect();
}

function nextSlideshowItem()
{
	clearTimeout(slideshow_timer_1);
	clearTimeout(slideshow_timer_2);
	
	(document.getElementById("slideshow_image_" + previous_item_nr)).style.visibility = "hidden";
	opacity("slideshow_image_" + previous_item_nr, 100, 0, 0);

	toonItemDirect();
}

function startSlideshow(img_path)
{		

	var slideshow_button = document.getElementById("button_start_slideshow");
	
	if(slideshow_status == "stopped")
	{
		if(aantal_items > 1)
		{	
			slideshow_button.src = pad + "" + img_path + "button_pause_slideshow.gif";
				
			slideshow_status = "running";
			
			toonItem();
		}
		else if(aantal_items > 0)
		{			
			(document.getElementById("slideshow_image_1")).style.visibility = "visible";
			
			opacity("slideshow_image_1", 70, 100, 1000);
		}
	}
	else
	{
		stopSlideshow(img_path);
	}
}

function stopSlideshow(img_path)
{
	var button = document.getElementById("button_start_slideshow");
	
	button.src = pad + "" + img_path + "button_start_slideshow.gif";

	clearTimeout(slideshow_timer_1);
	clearTimeout(slideshow_timer_2);
	
	slideshow_status = "stopped";
}



function toonItem()
{
	if(item_nr > aantal_items)
	{									
		item_nr = 1;
	}
	else if(item_nr < 1)
	{
		item_nr = aantal_items;
	}
	
	(document.getElementById("slideshow_image_" + item_nr)).style.visibility = "visible";
	//alert(previous_item_nr);
	opacity(('slideshow_image_' + item_nr), 0, 100, 2000);
	
	if(slideshow_status == "running")
	{
		slideshow_timer_1 = setTimeout("opacity(('slideshow_image_" + item_nr + "'), 100, 0, 2000);", 6000);
	}
	
	previous_item_nr = item_nr;
	
	item_nr++;
	
	if(slideshow_status == "running")
	{
		slideshow_timer_2 = setTimeout("toonItem();", 6000);
	}
}

function toonItemDirect()
{
	if(item_nr > aantal_items)
	{									
		item_nr = 1;
	}
	else if(item_nr < 1)
	{
		item_nr = aantal_items;
	}
	
	(document.getElementById("slideshow_image_" + item_nr)).style.visibility = "visible";		
	//opacity(('slideshow_image_' + item_nr), 0, 100, 0);
	opacity(('slideshow_image_' + item_nr), 99, 100, 0);
	//opacity(('slideshow_image_' + previous_item_nr), 100, 0, 0);
	
	if(slideshow_status == "running")
	{
		slideshow_timer_1 = setTimeout("opacity(('slideshow_image_" + item_nr + "'), 100, 0, 2000);", 6000);
	}
		
	previous_item_nr = item_nr;
	
	item_nr++;
	
	if(slideshow_status == "running")
	{
		slideshow_timer_2 = setTimeout("toonItem();", 6000);
	}
}