var off = 0;
var stopped;


function moveIn(thumb) {
  thumb.className="thumbimagein";
  off = 1;
  slideGoto(thumb);
}

function moveOut(thumb) {
  thumb.className="thumbimageout";
  off = 0;
  //slideGoto(thumb);
}

function slideGoto(thumb) {
  slideSwitch(getImageFromThumb(thumb));
}

function getImageFromThumb(thumb) {
  if (thumb == null) {
  return null;
  }
   
  var images = document.getElementById('slideshow').childNodes; 
  for ( var i = 0; i < images.length; i++ ) {
  var node = images.item(i);
  if (node.nodeName == 'IMG' && thumb.src == node.src) {
  return node;
  }
  }
   
  return null;
}

function slideSwitch(nextImage) {

  if (off > 0 && nextImage == null) return;

  var $active = $('#slideshow IMG.active');

  if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

  var $next = $active.next().length ? $active.next()
  : $('#slideshow IMG:first');
  if (nextImage != null) $next = $(nextImage);

  $active.addClass('last-active');
 

  $next.css({opacity: 0.0})
  .addClass('active')
  .animate({opacity: 1.0}, 1000, function() {
  $active.removeClass('active last-active');
  });
   
 $('#slideshow IMG.active')
  .click( function(event) { 
   
   
  slideSwitch(null);
   
   
  });  
}

$(function() {

  setInterval( "slideSwitch(null)", 5000 );
   
  $('#slideshow IMG.active')
  .click( function(event) { 
   
   
  slideSwitch(null);
   
   
  }); 
   
   
   
});



