var slide_count = 5;
var slide_index = 0;
var play_show = true;
var timeout = null;

if (window.addEventListener) 
{
  window.addEventListener('load', change_slide, false);
} 
else if (window.attachEvent) 
{
  window.attachEvent('onload', change_slide);
} 
else
{
  window.onload = change_slide;
}

function change_slide()
{
  if (timeout)
  {
    clearTimeout(timeout);
    timeout = null;
  }

  if (slide_index < 0 || slide_index >= slide_count)
  {
    slide_index = 0;
  }  
  
  for (var i = 0; i < slide_count; i++)
  {
    var image = get_slide_image(i);
    if (image)
    {
// like to get effects into this transitions...
//      if (i == slide_index) {
//	  		image.appear();
//	  } else {
//	  		image.hide();
//	  }
	  image.style.display = i == slide_index ? 'block' : 'none';
    }

    var command = get_slide_command(i);
    if (command)
    {
      command.className = i == slide_index ? 'current' : '';
    }
  }  
  
  if (play_show)
  {
    timeout = setTimeout('next_slide()', 10000);
  }
}

function next_slide()
{
  slide_index++;
  change_slide();
}

function select_slide(index)
{
  slide_index = index;
  change_slide();
}

function continue_slideshow(play)
{
  $('pause_slideshow').style.display = play ? 'block' : 'none';
  $('play_slideshow').style.display = play ? 'none' : 'block';
  play_show = play;
  change_slide();
}

function get_slide_image(index)
{
  return $('slide_image_' + index);
}

function get_slide_command(index)
{
  return $('slide_command_' + index);
}
