var Rotator = {
  intervalHandle: null,
  interval: 7000,
  count: null,
  index: null,
  
  init: function(count) {
    this.index = 1;
    this.count = count;
    if(count > 1) {
      this.intervalHandle = setInterval('Rotator.rotate()', this.interval);
    }
  },
  
  rotate: function() {
    if(this.count > 1) {
      this.index++;
      if(this.index > this.count) {
        this.index = 1;
      }
      this.performRotate();
    }
  },
  
  rotateTo: function(position) {
    this.index = position;
    if(this.intervalHandle) {
      clearInterval(this.intervalHandle);
      this.intervalHandle = null;
    }
    this.performRotate();
  },
  
  performRotate: function() {
    var index = this.index;
    var save = $('#footer').position();
    $('.rotator.active').fadeOut('fast', function() {
      $('.rotator.active').removeClass('active');
      $('#rotator-' + index).fadeIn('fast', function() {
        $('#rotator-' + index).addClass('active');
        //This hack is for ie6 which foolishly resizes the content area on rotation
        if(save.top != $('#footer').position().top) {
          $('#footer').css('top', '0px');
        }
      });
    });
  }
};
