var index = 1;
var photo_index  = 1;
var num_tips = 6;
var num_photos = 4;
var run_init = true;
var interval = 10 * 1000;


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

  //hide_morph = new Fx.Morph();
  //show_morph = new Fx.Morph();
  prep_rotation();
  setTimeout('switch_byte();', 10000);
  setTimeout('switch_photo();', 10000);
  
  
  if(typeof(has_callouts) != 'undefined')
  {
    
    SqueezeBox.initialize({
        size: {x: 431, y: 329}
    });
  
    //SqueezeBox.assign($$('a[rel=boxed]'));
    SqueezeBox.assign($$('a[rel=boxed]'), {
  		size: {x: 431, y: 329}
    });
    
	
  }
  
});

function switch_byte()
{
	
	var next_tip_index = index + 1;
	
	if(next_tip_index > num_tips)
	{
	
	  next_tip_index = 1;
	
	}
	
	//alert("next_tip_index: " + next_tip_index + " index: " + index);
	
	var tip_to_hide = "tip" + index;
	var tip_to_show = "tip" + 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_tips)
	{
	
	  index = 1;
	  
	}
	
	setTimeout('switch_byte()', interval)
	
}

function switch_photo()
{
  
  var next_photo_index = photo_index + 1;
	
	if(next_photo_index > num_photos)
	{
	
	  next_photo_index = 1;
	
	}
	
	//alert("next_photo_index: " + next_photo_index + " photo_index: " + photo_index);
	
	var photo_to_hide = "main_photo_" + photo_index;
	var photo_to_show = "main_photo_" + next_photo_index;

    var photo_hide_morph = new Fx.Morph(photo_to_hide, { 'duration': 1000 });
    var photo_show_morph = new Fx.Morph(photo_to_show, { 'duration': 1000 });
  
  // try to initialize the effect to avoid weird jarring switch the first 
  // time around

    photo_hide_morph.start({ 'opacity': '0' });
    photo_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;
	
	photo_index++;

	if(photo_index > num_photos)
	{
	
	  photo_index = 1;
	  
	}
	
	setTimeout('switch_photo()', interval)
}

function prep_rotation()
{

  for (var i = 1; i <= num_tips; i++)
  {
  
    var tip_to_prep = "tip" + 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('tip1', { 'duration': 0 });
  first_morph.start({ 'opacity': '1' });

}

function shrink()
{
  var next_tip_index = index + 1;
	
	if(next_tip_index > 3)
	{
	
	  next_tip_index = 1;
	
	}
	
	var tip_to_hide = "tip" + index;
	var tip_to_show = "tip" + next_tip_index;
	
  hide_morph = new Fx.Morph(tip_to_hide, { 'duration': 2000 });
  show_morph = new Fx.Morph(tip_to_show, { 'duration': 2000 });
  
  hide_morph.start({ 'opacity': '0' });
  show_morph.start({ 'opacity': '1' });
  
  //alert("showing: " + tip_to_show + " hiding: " + tip_to_hide);
  
	//$(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_tips)
	{
	
	  index = 1;
	  
	}
	
	alert();
	setTimeout('shrink()', interval);
	
}
