var current_id = 1;
var prev_id = 0;
var timer = 0;
var slides = new Array();

function startSlideshow(id, length, isStarting) {
  if (isStarting) {
    prev_id = length;
    current_id = 1;
  }
  else {
    prev_id = current_id;
    ++current_id;
  }

  if (current_id > length) {
    prev_id = length;
    current_id = 1;
  }

  new Effect.Fade('slide_' + id + '_' + prev_id);
  new Effect.Appear('slide_' + id + '_' + current_id);
  timer = window.setTimeout('startSlideshow("' + id + '",' + length + ')', 3000);
} 

function showVisual(id, type, file) {
  if (type != 'pdf') {
    elementID = 'visual_' + id;
    activeVisual = document.getElementsByClassName('activeVisual');
    appletElement = activeVisual[0].getElementsByTagName('applet');

    if (!appletElement[0]) {
      //
      // not currently showing a tour, so fade out will work
      //
      Effect.Fade(activeVisual[0],
	{ duration: 0.4,
	  afterFinish: function() {
	    Element.removeClassName(activeVisual[0], 'activeVisual');
	    Element.addClassName(activeVisual[0], 'inactiveVisual');
	    if (type != 'tour') {
	      //
	      // not going to show a tour, so fade in will work
	      //
	      Effect.Appear(elementID,
		  { duration: 0.4,
		    afterFinish: function() {
		      Element.removeClassName(elementID, 'inactiveVisual');
		      Element.addClassName(elementID, 'activeVisual');
		    }
		  } );
	      if (type == 'slide') {
		startSlideshow(id, slides[id], true);
	      }
	    }
	    else {
	      //
	      // show applet without trying to fade
	      //
	      Element.show(elementID);
	      Element.removeClassName(elementID, 'inactiveVisual');
	      Element.addClassName(elementID, 'activeVisual');
	    }
	  }
	} );
    }
    else {
      Element.hide(activeVisual[0]);
      Element.removeClassName(activeVisual[0], 'activeVisual');
      Element.addClassName(activeVisual[0], 'inactiveVisual');
      if (type != 'tour') {
	//
	// not going to show a tour, so fade in will work
	//
	Effect.Appear(elementID,
	  { duration: 0.4,
	    afterFinish: function() {
	      Element.removeClassName(elementID, 'inactiveVisual');
	      Element.addClassName(elementID, 'activeVisual');
	    }
	  } );
      }
      else {
	//
	// show applet without trying to fade
	//
	Element.show(elementID);
	Element.removeClassName(elementID, 'inactiveVisual');
	Element.addClassName(elementID, 'activeVisual');
      }
    }
  }
  else {
    window.open(file,'visual', 'location=0,menubar=0,resizable=1,width=800,height=600,toolbar=0');
  }
}

