var current_slideshow_id = '';
var current_slideshow_order = 0;
var loop_slideshow = true;
var timeout_slideshow;
var old_onclick_beeld_bg;

function startSlideshow(fotoOrder) {

	if ( current_slideshow_id=='' )
		return;
	
	if ( fotoOrder==null )
		current_slideshow_order = 0;
	else
		current_slideshow_order = fotoOrder;
		
	new Ajax.Updater('beeld_content', '/slideshows/'+current_slideshow_id+'/'+current_slideshow_order, {
                      evalScripts: true,
                      asynchronous: false
                    });
	showBeeldVerhaal();
	
	loop_slideshow = true;
	old_onclick_beeld_bg = $('beeld_bg').onclick;
	$('beeld_bg').onclick = function() {stopSlideshow();};
}


function automatic_slideshow_update(url)
{
	if ( loop_slideshow==true )
		updateSlideShow(url);
}


function updateSlideShow(url) {
	clearTimeout(timeout_slideshow);
	new Effect.Fade('beeld_content', { duration: 1, from: 1, to: 0.0, queue: {position:'end', scope: 'beeldverhaal'} });
	
	setTimeout("changeBeeldVerhaalContent('"+url+"');", 1000);
}

function stopSlideshow()
{
	timeout_slideshow = null;
	loop_slideshow = false;
	new Effect.Fade('beeld_content', { duration: 1, from: 1, to: 0.0, queue: {position:'end', scope: 'beeldverhaal'} });
	new Effect.Fade('beeld_bg', { duration: 0.5, from: 0.8, to: 0.0, queue: {position:'end', scope: 'beeldverhaal'} });
	$('beeld_bg').onclick = old_onclick_beeld_bg;
}

function changeSlideshowContent(url)
{
	changeBeeldVerhaalContent(url);
}

function restart_slideshow(url)
{
	if ( loop_slideshow==false )
	{
		clearTimeout(timeout_slideshow);
		loop_slideshow = true;
		timeout_slideshow = setTimeout("automatic_slideshow_update('"+url+"');", 1000);
	}
}

function pause_slideshow()
{
	clearTimeout(timeout_slideshow);
	loop_slideshow = false;
}

function search_slideshow_foto()
{
	var foto = $('txtFoto').value;
	
	if ( IsNumeric(foto) )
	{
		pause_slideshow();
		foto = foto -1;
		updateSlideShow('/slideshows/' + current_slideshow_id + '/' + foto);
	}
}


function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
      	IsNumber = false;
      }
   }
   
   return IsNumber;   
}


