var dodgingdiabetes;
dodgingdiabetes = dodgingdiabetes || {};

/** 
 * Function for the image rotator for the top image.
 *
 * @param container (optional) - jQuery object or value that can be turned into jQuery object. Default: #photo .inner.
 * @param time (optional) - The time in milliseconds to rotate. Default: 5 seconds.
 */
dodgingdiabetes.imageRotator = function( container, time ){
  time = parseInt( time ) || 8000;
  container = container || '#photo .inner';
  container = jQuery( container );
  var containerHeight = container.height( );
  var images = container.find( 'img' );
  images.not( ':first' ).hide( );
  
  var current = images.filter( ':first' );
  
  var trans = function( ){
    var next = current.next( 'img' );
    if( next.size( ) == 0 ){
      next = images.filter( ':first' );
    }
    
    next
      .css( { 
        'bottom': containerHeight+'px',
        'zIndex': 5,
        'display': 'block' } )
      .animate( 
        { 'bottom': 0 },
        3500,
        'easeOutBounce',
        function( ){
          current.hide( );
          current = next;
          current.css( 'z-index', '' );
        }
      );
  };
  
  trans( );
  setInterval( trans, time ); 
};


//
// Auto load stuff
//

jQuery( document ).ready( function( ){
  dodgingdiabetes.imageRotator( );
 } );