function CGallery(AName, AContainer, APicker)
{
  AContainer.innerHTML = '<div id="gallery_' + AName + '_container_1"></div><div id="gallery_' + AName + '_container_2"></div>';

  this.Name = AName;
  this.Container1 = document.getElementById('gallery_' + AName + '_container_1');
  this.Container2 = document.getElementById('gallery_' + AName + '_container_2');
  this.Picker = APicker;
  this.CurrentContainer = 0;
  this.CurrentPicture = 0;

  this.Animated = false;
  this.AnimateInterval = 0;
  this.AnimationTimer = null;

  this.Pictures = new Array();

  this.AddPicture = function(APicture)
  {
    this.Pictures[this.Pictures.length] = APicture;
  }

  this.Initialize = function()
  {
    if (this.Pictures.length > 0)
    {
      this.Container1.style.zIndex = 20;
      this.Container2.style.zIndex = 10;

      this.Container1.style.display = '';
      this.Container1.style.backgroundImage = "url('" + this.Pictures[0] + "')";

      this.CurrentContainer = 1;

      // Render all numbers
      if (this.Pictures.length > 1)
      {
        PickerHTML = '';

        Picture = 0;
        while (Picture < this.Pictures.length)
        {
          PickerHTML = PickerHTML + '<a href="javascript: ' + this.Name + '.SelectPicture(' + Picture + ');" id="gallery_' + this.Name + '_selector_' + Picture + '">' + (Picture + 1) + '</a>';

          Picture++;
        }

        this.Picker.innerHTML = PickerHTML;
      }

      // Select the first picture picker
      $('#gallery_' + this.Name + '_selector_0').addClass('selected');
    }
  }

  this.SelectPicture = function(APicture)
  {
    if (APicture != this.CurrentPicture)
    {
      // Clear picker
      $('#' + this.Picker.id + ' > *').removeClass('selected');

      if (this.CurrentContainer == 1)
      {
        this.Container2.style.display = 'none';
        this.Container1.style.zIndex = 10;
        this.Container2.style.zIndex = 20;
        $('#' + this.Container2.id).css('background-image', "url('" + this.Pictures[APicture] + "')");
        $('#' + this.Container2.id).fadeIn(500);

        this.CurrentPicture = APicture;
        this.CurrentContainer = 2;
      }
      else
      {
        this.Container1.style.display = 'none';
        this.Container2.style.zIndex = 10;
        this.Container1.style.zIndex = 20;
        $('#' + this.Container1.id).css('background-image', "url('" + this.Pictures[APicture] + "')");
        $('#' + this.Container1.id).fadeIn(500);

        this.CurrentPicture = APicture;
        this.CurrentContainer = 1;
      }

      $('#gallery_' + this.Name + '_selector_' + this.CurrentPicture).addClass('selected');
    }

    // Reset timer
    if (this.Animated)
    {
      clearTimeout(this.AnimationTimer);
      this.AnimationTimer = setTimeout(this.Name + '.SelectPicture(' + (this.CurrentPicture + 1 == this.Pictures.length ? 0 : this.CurrentPicture + 1) + ')', this.AnimateInterval);
    }
  }

  this.Animate = function(AInterval)
  {
    this.Animated = true;
    this.AnimateInterval = AInterval;

    this.AnimationTimer = setTimeout(this.Name + '.SelectPicture(' + (this.CurrentPicture + 1 == this.Pictures.length ? 0 : this.CurrentPicture + 1) + ')', this.AnimateInterval);
  }
}

