var diashow = new Array();

function diashow_autoplay_start( id )
{
	diashow[id].play = true;
	var img = $('diashow' + id + 'playpausebutton');
	img.src = img.src.replace(/play\.gif/, 'pause.gif');

	var link = $('diashow' + id + 'playpauselink');
	link.href = link.href.replace(/start/, 'stop');

	diashow[id].timeout = setTimeout("diashow_play(" + id + ")", diashow[id].pause * 1000 );
}

function diashow_autoplay_stop( id )
{
	diashow[id].play = false;
	window.clearTimeout( diashow[id].timeout );
	
	var img = $('diashow' + id + 'playpausebutton');
	img.src = img.src.replace(/pause\.gif/, 'play.gif');

	var link = $('diashow' + id + 'playpauselink');
	link.href = link.href.replace(/stop/, 'start');
}

function diashow_play( id )
{
	if( !diashow[id].play )
		return;

	// If last, start over...
	if( diashow[id].current >= (diashow[id].total-1) )
	{
		diashow[id].current = 0;
		eval("diashow_" + diashow[id].effect + "( id, diashow[id].total-1, 1 );");
		diashow_update( id );
		diashow_updatebuttons( id );
	}
	else
		diashow_next( id, false );

	setTimeout("diashow_play(" + id + ")", diashow[id].pause * 1000 );
}

function diashow_next( id, manual )
{
	if( diashow[id].play && manual )
		diashow_autoplay_stop(id);

	if( (diashow[id].total-1) > diashow[id].current )
	{
		diashow[id].current++;
		eval("diashow_" + diashow[id].effect + "( id, diashow[id].current-1, 1 );");
		diashow_update( id );

		$('diashowprev' + id ).fade(1);
	}

	diashow_updatebuttons( id );
}

function diashow_updatebuttons( id )
{
	// Next button
	if( (diashow[id].total-1) == diashow[id].current )
		$('diashownext' + id ).fade(0.2);
	else
		$('diashownext' + id ).fade(1);

	// Prev button
	if( diashow[id].current == 0 )
		$('diashowprev' + id ).fade(0.2);
	else
		$('diashowprev' + id ).fade(1);
}

function diashow_prev( id, manual )
{
	if( diashow[id].play && manual )
		diashow_autoplay_stop(id);

	if( diashow[id].current > 0 )
	{
		diashow[id].current--;
		eval("diashow_" + diashow[id].effect + "( id, diashow[id].current+1, -1 );");
		diashow_update( id );

		$('diashownext' + id ).fade(1);
	}

	diashow_updatebuttons( id );
}

function diashow_update( id )
{
	// Update beschrijving
	if( diashow[id].descriptions[ diashow[id].current ].length == 0 )
	{
		$('diashowoverlay' + id).fade(0);
		$('diashowdesc' + id).fade(0);
	}
	else
	{
		$('diashowdesc' + id).innerHTML = diashow[id].descriptions[ diashow[id].current ];
		$('diashowoverlay' + id).fade(1);
		$('diashowdesc' + id).fade(1);
	}

	// Update huidige foto nr
	$('diashowcurrent' + id).innerHTML = diashow[id].current+1;
}

function diashow_fade( id, prev, direction )
{
	// Laat de goede <img> zien
	for( var i = 0; i < diashow[id].total; i++ )
	{
		var obj = $('diashowimg' + id + '_' + i );

		if( i == diashow[id].current )
		{
			// Nieuwe afbeelding
			var tween = $(obj).get('tween', {property: 'opacity', duration: diashow[id].transition*1000});
			tween.set(0);
			$(obj).style.display = 'block';
			tween.start(1);
		}
		else
		{
			// Oude
			$(obj).get('tween', {property: 'opacity', duration: diashow[id].transition*1000}).start(0);
		}
	}
}

function diashow_slidey( id, prev, direction )
{
	// Laat de goede <img> zien
	for( var i = 0; i < diashow[id].total; i++ )
	{
		var obj = $('diashowimg' + id + '_' + i );

		if( i == diashow[id].current )
		{
			// Nieuwe afbeelding
			var tween = $(obj).get('tween', {property: 'top', duration: diashow[id].transition*1000});
			tween.set(diashow[id].height * direction);
			$(obj).style.display = 'block';
			tween.start([diashow[id].height * direction, 0]);
		}
		else if( i == prev )
		{
			// Oude
			$(obj).get('tween', {property: 'top', duration: diashow[id].transition*1000}).start([0, -1 * diashow[id].height * direction]);
		}
		else
			$(obj).style.display = 'none';
	}
}

function diashow_slidex( id, prev, direction )
{
	// Laat de goede <img> zien
	for( var i = 0; i < diashow[id].total; i++ )
	{
		var obj = $('diashowimg' + id + '_' + i );

		if( i == diashow[id].current )
		{
			// Nieuwe afbeelding
			var tween = $(obj).get('tween', {property: 'left', duration: diashow[id].transition*1000});
			tween.set(diashow[id].width * direction);
			$(obj).style.display = 'block';
			tween.start([diashow[id].width * direction, 0]);
		}
		else if( i == prev )
		{
			// Oude
			$(obj).get('tween', {property: 'left', duration: diashow[id].transition*1000}).start([0, -1 * diashow[id].width * direction]);
		}
		else
			$(obj).style.display = 'none';
	}
}
