// Setup the count of images...
var last_image = 4;
var cnt_image = 4;

// Rotate/Fading Functions
//
function next_step()
{
    var desired_fps = 30;
    var transition_seconds = 2;
    var timer_amt = 1000 / desired_fps;
    var inc_amt = 100 / desired_fps / transition_seconds;

    if ( cnt_image == last_image )
    {
        // If we're at the last image in sequence, we need to blink all
        // the other images up before fading down

        var i;
        for ( i = 1; i < last_image; ++i )
        {
            blink_in( 'rotate' + i );
        }
    }

    if ( cnt_image > 1 )
    {
        var next_image = cnt_image;
        --cnt_image;
        fade_out( 'rotate' + next_image, 100, inc_amt, timer_amt, 'wait_next_step();' );
    }
    else
    {
        // Otherwise we need to fade the last image back in.
        cnt_image = last_image;
        fade_in( 'rotate' + last_image, 0, inc_amt, timer_amt, 'wait_next_step();');
    }
}

function wait_next_step()
{
     setTimeout( 'next_step()', 2000 );
}


function fade_in( element, cnt, increment, timer, done )
   {
      if ( cnt > 100 )
      {
        cnt = 100;
      }

      eval( 'document.getElementById("' + element + '").style.opacity=' + ( cnt / 100 )+ ';' );
      eval( 'document.getElementById("' + element + '").style.filter="alpha(opacity:' + cnt + ')";' );
      if ( cnt < 100 )
      {
         var str = "fade_in( '" + element + "', ";

         str = str + ( cnt - (-increment) ) + ", " + increment + ", " + timer + ", '" + done + "' )";

         setTimeout( str, timer );
      } 
      else if ( done != "" )
      {
         eval( done );
      }
   }

   function fade_out( element, cnt, increment, timer, done )
   {
      if ( cnt < 0 )
      {
        cnt = 0;
      }

      eval( 'document.getElementById("' + element + '").style.opacity=' + ( cnt / 100 )+ ';' );
      eval( 'document.getElementById("' + element + '").style.filter="alpha(opacity:' + cnt + ')";' );
      if ( cnt > 0  )
      {
         var str = "fade_out( '" + element + "', ";
         
         str = str + ( cnt - increment ) + ", " + increment + ", " + timer + ", '" + done + "' )";
         
         setTimeout( str, timer );
      } 
      else if ( done != "" )
      {
         eval( done );
      }
   }

   function blink_out( element )
   {
      eval( 'document.getElementById("' + element + '").style.opacity=0;' );
      eval( 'document.getElementById("' + element + '").style.filter="alpha(opacity:0)";' );
   }

   function blink_in( element )
   {
      eval( 'document.getElementById("' + element + '").style.opacity=1;' );
      eval( 'document.getElementById("' + element + '").style.filter="alpha(opacity:100)";' );
   }



