/**
 * Multimedia area.
 *
 * Requires Prototype 1.6.
 */
var gAjaxFetchVideoViewURL = '/home_links/__ID__';

// Adding a useful method to UI.Carousel…
UI.Carousel.addMethods({
  scrollIntoView: function(position) {
    var first = this.currentIndex(), last = first + this.nbVisible - 1;
    if (first <= position && position <= last) return;
    if (position > last)
      this.scrollTo(position - this.nbVisible + 1);
    else
      this.scrollTo(position);
  }
});

function initPhotoArea() {
  var majorLinksCarousel = new UI.Carousel('majorLinksCarousel');
/*
  $('majorLinksCarousel').select('.nav').invoke('observe', 'click', function(e) {
    e.stop();
    this.blur();
  });
*/
  var slideshow = new SlideShow('photoZone', 'majorLinksCarousel', {
    ajaxLoadingURL: gAjaxFetchPhotoViewURL,
    indicator: '/images/spinner_large.gif',
    cycle: true,
    speed: 'slow',
    uiBindings: {
      previous: 'btnPrevPhoto', next: 'btnNextPhoto', toggle: 'btnPlayPause'
    },
    beforeSlideChange: function(slideShow, position) {
      majorLinksCarousel.scrollIntoView(position);
    }
  });
  slideshow && slideshow.resume();
} // initPhotoArea

document.observe('dom:loaded', function() {
  initPhotoArea();
});
