(function() {
  var $;

  $ = jQuery;

  (function() {
    var stopClicked, t;
    if ($.browser.msie) {
      ($("#slides,#magnify-glass, #prev-arrow, #next-arrow")).css("opacity", 0);
    }
    ($('#preload-image')).waitForImages(function() {
      clearInterval(t);
      ($('#spinner')).fadeOut(600).remove();
      return ($('#magnify-glass, #slides, #prev-arrow, #next-arrow')).animate({
        'opacity': 1
      }, 3000, 'linear', function() {
        if ($.browser.msie) {
          return ($('#magnify-glass')).css({
            'filter': '"progid:DXImageTransform.Microsoft.AlphaImageLoader(src=fig0902.png,sizingMethod=\'scale\')"'
          });
        }
      });
    });
    stopClicked = false;
    t = setInterval(function() {
      if (stopClicked) {
        ($("#home-page #slides, #magnify-glass")).remove();
        return clearInterval(t);
      }
    }, 100);
    return ($("#spinner a")).live("click", function(event) {
      event.preventDefault();
      stopClicked = true;
      ($('#spinner')).fadeOut().remove();
      ($('#prev-arrow, #next-arrow')).remove();
      return ($("#staticImage")).fadeIn("slow");
    });
  })();

  ($(document)).ready(function() {
    var arrowVisible, bookNum, int, leftA, rightA;
    window.BookSlideArrow = (function() {

      function BookSlideArrow(selector, direction, num) {
        this.selector = selector;
        this.direction = direction;
        this.num = num;
      }

      BookSlideArrow.prototype.slide = function() {
        var _this = this;
        return ($(this.selector)).click(function(event) {
          var controlIndex, currentIndex, currentMargin, moveValue, num;
          event.preventDefault();
          currentMargin = parseInt(($("#nona_books ul")).css("margin-left"));
          currentIndex = ($("#nona_books li.curIndex")).index();
          controlIndex = (function() {
            switch (this.direction) {
              case "left":
                return controlIndex = currentIndex - 1;
              case "right":
                return controlIndex = currentIndex + 1;
            }
          }).call(_this);
          num = (_this.num - 1) * (-371);
          if (controlIndex > currentIndex) {
            currentIndex = ($("#nona_books li.curIndex")).index();
            currentIndex++;
            moveValue = currentMargin - 371;
          } else if (controlIndex < currentIndex) {
            currentIndex = ($("#nona_books li.curIndex")).index();
            currentIndex--;
            moveValue = currentMargin + 371;
          }
          return ($("#nona_books ul:not(:animated)")).stop().animate({
            "margin-left": moveValue
          }, 600, "linear", function() {
            currentMargin = parseInt(($("#nona_books ul")).css("margin-left"));
            ($("#nona_books li.curIndex")).removeClass('curIndex');
            ($("#nona_books li:eq(" + controlIndex + ")")).addClass('curIndex');
            ($(".controls li.current")).removeClass('current');
            ($(".controls li:eq(" + controlIndex + ")")).addClass('current');
            return arrowVisible(currentMargin, num);
          });
        });
      };

      return BookSlideArrow;

    })();
    bookNum = ($('#nona_books li')).length;
    ($("#nona_books li:eq(0)")).addClass("curIndex");
    int = 0;
    while (int < bookNum) {
      ($('.controls ul')).append('<li></li>');
      int++;
    }
    ($('.controls')).width(bookNum * 23).find('ul li:eq(0)').addClass('current');
    leftA = new BookSlideArrow("#book_flip_left", "left", bookNum);
    rightA = new BookSlideArrow("#book_flip_right", "right", bookNum);
    leftA.slide();
    rightA.slide();
    ($('.controls li')).click(function(event) {
      var controlIndex, currentIndex, currentMargin, move, moveValue, num;
      event.preventDefault();
      currentIndex = ($("#nona_books li.curIndex")).index();
      controlIndex = ($(event.target)).index();
      num = (bookNum - 1) * (-371);
      currentMargin = parseInt(($("#nona_books ul")).css("margin-left"));
      ($(".controls li.current")).removeClass('current');
      ($(".controls li:eq(" + controlIndex + ")")).addClass('current');
      if (controlIndex > currentIndex) {
        move = controlIndex - currentIndex;
        moveValue = currentMargin + move * (-371);
        ($("#nona_books ul:not(:animated)")).stop().animate({
          "margin-left": moveValue
        }, 600, "linear", function() {
          ($("#nona_books li.curIndex")).removeClass('curIndex');
          ($("#nona_books li:eq(" + controlIndex + ")")).addClass('curIndex');
          return arrowVisible(moveValue, num);
        });
      }
      if (controlIndex < currentIndex) {
        move = currentIndex - controlIndex;
        moveValue = currentMargin - move * (-371);
        ($("#nona_books ul:not(:animated)")).stop().animate({
          "margin-left": moveValue
        }, 600, "linear", function() {
          ($("#nona_books li.curIndex")).removeClass('curIndex');
          ($("#nona_books li:eq(" + controlIndex + ")")).addClass('curIndex');
          return arrowVisible(moveValue, num);
        });
      }
      if (controlIndex === currentIndex) {}
    });
    return arrowVisible = function(currentMargin, num) {
      if (currentMargin === 0) {
        ($("#book_flip_left")).hide();
      } else if (currentMargin !== 0) {
        if (($("#book_flip_left")).css('display') !== "block") {
          ($("#book_flip_left")).show();
        }
      }
      if (currentMargin === num) ($("#book_flip_right")).hide();
      if (currentMargin !== num) {
        if (($("#book_flip_right")).css('display') !== "block") {
          return ($("#book_flip_right")).show();
        }
      }
    };
  });

}).call(this);

