(function ($) {
  
  Drupal.behaviors.customSlideshowPagerDots = {
    attach: function (context) {
      // Process pause on hover.
      $('.custom-slideshow-pager-dots:not(.custom-slideshow-pager-dots-processed)', context).addClass('custom-slideshow-pager-dots-processed').each(function() {
        // Parse out the location and unique id from the full id.
        var pagerInfo = $(this).attr('id').split('_');
        var location = pagerInfo[2];
        pagerInfo.splice(0, 3);
        var uniqueID = pagerInfo.join('_');
        
        // Add the activate and pause on pager hover event to each pager item.
        $(this).children().each(function(index, pagerItem) {
          $(pagerItem).hover(function() {
            Drupal.viewsSlideshow.action({ "action": 'goToSlide', "slideshowID": uniqueID, "slideNum": index });
            Drupal.viewsSlideshow.action({ "action": 'pause', "slideshowID": uniqueID });
          },
          function() {
            Drupal.viewsSlideshow.action({ "action": 'play', "slideshowID": uniqueID });
          });
        });
      });
    }
  };
  
  Drupal.customSlideshowPagerDots = Drupal.customSlideshowPagerDots || {};

  Drupal.customSlideshowPagerDots.transitionBegin = function (options) {
    // Remove active class from pagers
    $('[id^="custom_dots_"]').removeClass('active');
    
    // Add active class to active pager.
    $('#custom_dots_' + options.slideNum).addClass('active');
  }
  
})(jQuery);
;

