
$(document).ready(function() {
    var galleryWidth; var galleryHeight;
    if ($('.TierContent').length>0) {
        galleryWidth=475;
        galleryHeight=360;
    } else {
        galleryWidth=740;
        galleryHeight=503;
    }
    $('.adg-gallery').adGallery({
      loader_image: '/public/images/gallery/loader.gif',                     
      description_wrapper: $('#adg-image-descriptions'),
      width: galleryWidth, 
      height: galleryHeight, 
      thumb_opacity: 1, 
      slideshow: {
        enable: true,
        autostart: true,
        speed: 5000,
        start_label: '<u>S</u>tart slideshow',
        stop_label: '<u>S</u>top slideshow',
        stop_on_scroll: true, // Should the slideshow stop if the user scrolls the thumb list?
        countdown_prefix: '(', // Wrap around the countdown
        countdown_sufix: ')',
        onStart: function() {
          this.start_link.hide(); this.stop_link.show(); 
        },
        onStop: function() {
          this.stop_link.hide(); this.start_link.show(); 
        }
      },
      effect: 'none', 
      callbacks: {
        init: function() {
          this.preloadImage(0);
          this.preloadImage(1);
          this.preloadImage(2);
        },
        afterImageVisible: function() {
          var context = this;
          if(this.images[this.current_index + 1]) {
              this.loading(true);
              this.preloadImage(this.current_index + 1,
                function() {
                  context.loading(false);
                }
              );
          }
        }
      }
    });
});
