var Presentation = new function()
{
  /* Constants */
  this.CLASS_CONTAINER = '.top_content_ads';
  this.INTERVAL_CHANGE = 8000;
  this.INTERVAL_FADE = 1000;
  
  /* Variables */
  this.Container = null;
  this.Index = -1;
  this.List = [];
  this.Timer = null;

  /* Methods */
  this.Initialize = function()
  {
    this.Container = $(this.CLASS_CONTAINER);
    this.List = this.Container.find('a');
    this.List.remove();
    this.Container.html('').hide().mouseenter
    (
      this.MouseEnterEvent
    ).mouseleave
    (
      this.MouseLeaveEvent
    );
    
    this.List.appendTo(this.Container);
    
    if (this.List.length > 0)
      this.Next();
  };
  
  this.FadeOut = function()
  {
    $(this.Container).fadeOut(
      this.INTERVAL_FADE, function()
      {
        Presentation.Next();
      }
    );
  };
  
  this.Next = function()
  {
    if (this.Index != -1)
      $(this.List[this.Index]).hide();
  
    this.Index++;
    
    if (this.Index > this.List.length - 1)
      this.Index = 0;
      
    $(this.List[this.Index]).show();
    $(this.Container).fadeIn
    (
      this.INTERVAL_FADE, function()
      {
        Presentation.Timer = setTimeout('Presentation.FadeOut()', Presentation.INTERVAL_CHANGE);
      }
    );
  };
  
  /* Events */
  this.MouseEnterEvent = function()
  {
    clearTimeout(Presentation.Timer);
    $(Presentation.Container).stop().css('opacity', '1.0');
  };
  
  this.MouseLeaveEvent = function()
  {
    Presentation.Timer = setTimeout('Presentation.FadeOut()', Presentation.INTERVAL_CHANGE);
  };
};

$(window).load(
  function()
  {
    Presentation.Initialize();
  }
);
