/*!
 * @copyright 2010-Present Advanced Care Solutions, Inc.
 * @author Christopher Rahauiser <crahauiser@acs-web.com>
 */
(function($) {
  var customizableSlideShowContent = $('.customizable-slideshow-content');
  var contentWidth = 0,
      realContentWidth = customizableSlideShowContent.width();
  if (realContentWidth > 0) {
    contentWidth = realContentWidth;
  }

  var configuration = (function(w, rightToLeft) {
    var posWidth = w + 'px';
    var negWidth = '-' + posWidth;

    if (! rightToLeft) {
      var tmp = posWidth;
      posWidth = negWidth;
      negWidth = tmp;
    }

    function beforeNextAnimation(animateInObj, animateOutObj) {
      animateInObj.css('left', posWidth);
    }
    function beforePreviousAnimation(animateInObj, animateOutObj) {
      animateInObj.css('left', negWidth);
    }

    var animateInNextPreviousProperties = {
      left: 0
    };

    function animateInNextPreviousCallback() {
      $(this).css('zIndex', 2);
    }

    var animateOutNextProperties = {
      left: negWidth
    };
    var animateOutPreviousProperties = {
      left: posWidth
    };

    function animateOutNextCallback() {
      $(this).css('zIndex', 1);
    }
    function animateOutPreviousCallback() {
      $(this).css({
        left: negWidth,
        zIndex: 1
      });
    }

    function childrenSetup(children) {
      children.eq(0).css('zIndex', 2);
      children
        .not(':eq(0)')
          .css('left', negWidth)
          .show();
    }

    return {
      triggerDuration: 5000,
      animateInNextDuration: 1200,
      animateOutNextDuration: 1200,
      animateInPreviousDuration: 1200,
      animateOutPreviousDuration: 1200,
      nextSelector: $.fn.customizableSlideShow.defaults.nextSelector,
      previousSelector: $.fn.customizableSlideShow.defaults.previousSelector,
      childrenSetup: childrenSetup,
      beforeNextAnimation: beforeNextAnimation,
      animateInNextProperties: animateInNextPreviousProperties,
      animateInNextCallback: animateInNextPreviousCallback,
      animateOutNextProperties: animateOutNextProperties,
      animateOutNextCallback: animateOutNextCallback,
      beforePreviousAnimation: beforePreviousAnimation,
      animateInPreviousProperties: animateInNextPreviousProperties,
      animateInPreviousCallback: animateInNextPreviousCallback,
      animateOutPreviousProperties: animateOutPreviousProperties,
      animateOutPreviousCallback: animateOutPreviousCallback
    };
  })(contentWidth, true); // true - right to left, false - left to right

  customizableSlideShowContent.customizableSlideShow(configuration);
})(jQuery);
