window.log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){arguments.callee=arguments.callee.caller;var a=[].slice.call(arguments);(typeof console.log==="object"?log.apply.call(console.log,console,a):console.log.apply(console,a))}};
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try
{console.log();return window.console;}catch(err){return window.console={};}})());


(function ($) {
  $.fn.bannerSlider = function () {
    var animating = false;
    var itemWidth = 1224;
    var position = 0;
    var itemsWrapper = null;
    var items = 0;
    var timer = null;
    var timerTime = 7000;

    function animate(direction) {
      if (animating) {
        return;
      }

      position += direction;

      if (position < 0) {
        position = items.length - 1;
      } else if (position >= items.length) {
        position = 0;
      }

      animating = true;

      animateTo(position);

      return false;
    }

    function animateTo(location) {
      itemsWrapper.animate({ 'left': -(location * itemWidth) + 'px' }, 'slow', function () { animating = false; });
      $('.indicatorArrow').removeClass('active');
      $($('.indicatorArrow')[location]).addClass('active');
      position = location;
    }

    function moveNext() {
      animate(+1);
      timer = setTimeout(moveNext, timerTime);
    }

    return this.each(function () {
      itemsWrapper = $(this).children().first();
      items = itemsWrapper.children();

      itemsWrapper.css('width', items.length * itemWidth);

      $('.indicatorArrow').click(function () {
        clearTimeout(timer);
        animateTo($(this).prevAll().length - 1);
      });

      $(this).find('a#prevArrow').click(function () { clearTimeout(timer); animate(-1); });
      $(this).find('a#nextArrow').click(function () { clearTimeout(timer); animate(+1); });

      timer = setTimeout(moveNext, timerTime);
    });
  };
})(jQuery);
