var index = 17;
var num_tombs = 17;
var run_init = true;
// interval is in milliseconds 
// X * 1000 = X seconds
// 7 * 1000 = 7 seconds
var interval = 5.5 * 1000;


window.addEvent('domready', function() 
{

  //hide_morph = new Fx.Morph();
  //show_morph = new Fx.Morph();
  prep_rotation();
  setTimeout('switch_tomb();', 7000);
  
});

function switch_tomb()
{
	
	var next_tip_index = index + 1;
	
	if(next_tip_index > num_tombs)
	{
	
	  next_tip_index = 1;
	
	}
	
	//alert("next_tip_index: " + next_tip_index + " index: " + index);
	
	var tip_to_hide = "tomb_" + index;
	var tip_to_show = "tomb_" + next_tip_index;

    var hide_morph = new Fx.Morph(tip_to_hide, { 'duration': 1000 });
    var show_morph = new Fx.Morph(tip_to_show, { 'duration': 1000 });
  
  // try to initialize the effect to avoid weird jarring switch the first 
  // time around

    hide_morph.start({ 'opacity': '0' });
    show_morph.start({ 'opacity': '1' });

	//$(tip_to_hide).fx = $(tip_to_hide).effect('opacity', {duration: 1000}).start(0);
	//$(tip_to_show).fx = $(tip_to_show).effect('opacity', {duration: 1000}).start(1);
	
	//$(tip_to_hide).fx = null;
	//$(tip_to_show).fx = null;
	
	index++;

	if(index > num_tombs)
	{
	
	  index = 1;
	  
	}
	
	setTimeout('switch_tomb()', interval)
	
}

function prep_rotation()
{

  for (var i = 1; i <= num_tombs; i++)
  {
  
    var tip_to_prep = "tomb_" + i;
    var prep_morph = new Fx.Morph(tip_to_prep, { 'duration': 0 });
    
    // try to initialize the effect to avoid weird jarring switch the first 
    // time around

    prep_morph.start({ 'opacity': '0' });
  
  }
  
  var first_morph = new Fx.Morph('tomb_1', { 'duration': 0 });
  first_morph.start({ 'opacity': '1' });

}
