var $j = jQuery.noConflict();
var count = 0;
var countmax;
var delay = 10000;
var newheight = 0;
var currentelement = $j('#rotate IMG:eq('+count+')');

$j(document).ready(function(){
  currentelement = $j('#rotate IMG:eq('+count+')');
  countmax = $j('#rotate IMG').size() - 2;
  $j('#rotate IMG').each(function(){
    $j(this).css('display', 'none')
  });
  var start = $j('#rotate IMG:first');
  $j('#mask').hide();
  $j(currentelement).show();
  setInterval(fade, delay);
});
    
function trim(str, chars) {
  return ltrim(rtrim(str, chars), chars);
}
function fade(){
  $j('.nextBtn').hide();
  if(count <= countmax){
    count++;
    if(count == 0){
      
    }else{
      $j('#rotate IMG:eq('+(count-1)+')').fadeOut('slow', function(){
        newheight = $j('#rotate IMG:eq('+count+')').height();
        $j('#rotate IMG:eq('+count+')').css('height', $j('#rotate IMG:eq('+(count-1)+')').height()+'px');
        $j('#rotate IMG:eq('+count+')').fadeIn('slow', function(){
          $j('#rotate IMG:eq('+count+')').animate({height: newheight+'px'}, 'slow', function(){
        });
        });
        
      });
    }
    currentelement = $j('#rotate IMG:eq('+count+')');
    
  }else{
    $j('#rotate IMG').each(function(){
      currentelement = $j('#rotate IMG:eq('+count+')');
      count = 0;
    });
    $j('#rotate IMG:eq('+(countmax+1)+')').fadeOut('slow', function(){
      newheight = $j('#rotate IMG:eq('+count+')').height();
      $j('#rotate IMG:eq('+count+')').css('height', $j('#rotate IMG:eq('+(countmax+1)+')').height()+'px');
      $j('#rotate IMG:eq('+count+')').fadeIn('slow', function(){
        $j('#rotate IMG:eq('+count+')').animate({height: newheight+'px'}, 'slow', function(){
        });
      });
      
    });
  }
  return false;
}
