(function() {
  var Book, Bookshelf, JsBook, SwfBook;
  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
    for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
    function ctor() { this.constructor = child; }
    ctor.prototype = parent.prototype;
    child.prototype = new ctor;
    child.__super__ = parent.prototype;
    return child;
  };
  Book = (function() {
    function Book(id) {
      this.id = id;
    }
    Book.prototype.initField = function() {
      return $("#mainVisualBookshelf").append("<div id=\"mainVisualBook" + this.id + "\" class=\"mainVisualBook\"></div>");
    };
    Book.prototype.close = function() {
      var $book;
      $book = $("#mainVisualBook" + this.id);
      $book.css({
        "z-index": "1"
      });
      return $book.fadeOut(1000, __bind(function() {
        $book.css({
          "z-index": "0"
        });
        $book = $("#mainVisualBook" + this.id);
        $book.remove();
        return this.initField();
      }, this));
    };
    return Book;
  })();
  JsBook = (function() {
    __extends(JsBook, Book);
    function JsBook(book, id) {
      this.book = book;
      this.id = id;
      this.time = book.attr("time");
      this.href = book.attr("href");
      this.newwindow = book.attr("newwindow");
      this.bookImage = book.find("left smallbook").text();
      this.leftBGImage = book.find("left background").text();
      this.rightText1 = book.find("right text1").text();
      this.rightText2 = book.find("right text2").text();
      this.rightText3 = book.find("right text3").text();
      this.rightBGImage = book.find("right background").text();
      this.initField();
    }
    JsBook.prototype.init = function() {
      var $book, elm;
      $book = $("#mainVisualBook" + this.id);
      $book.css({
        "cursor": "pointer"
      });
      $book.click(__bind(function() {
        if (this.newwindow === "") {
          return location.href = this.href;
        } else {
          return window.open(this.href);
        }
      }, this));
      elm = "<img class=\"leftbg\" src=\"" + this.leftBGImage + "\" alt=\"\" />";
      elm += "<img class=\"book\" src=\"" + this.bookImage + "\" alt=\"\" />";
      elm += "<img class=\"rightbg\" src=\"" + this.rightBGImage + "\" alt=\"\" />";
      elm += "<img class=\"text1\" src=\"" + this.rightText1 + "\" alt=\"\" />";
      elm += "<img class=\"text2\" src=\"" + this.rightText2 + "\" alt=\"\" />";
      elm += "<img class=\"text3\" src=\"" + this.rightText3 + "\" alt=\"\" />";
      return $book.append(elm);
    };
    JsBook.prototype.play = function() {
      var $bg, $book;
      this.init();
      $book = $("#mainVisualBook" + this.id);
      $book.show();
      $bg = $book.find(".leftbg");
      $bg.show();
      return setTimeout(__bind(function() {
        return this.bookMoveFirst();
      }, this), 500);
    };
    JsBook.prototype.bookMoveFirst = function() {
      var $book, $innerBook;
      $book = $("#mainVisualBook" + this.id);
      $innerBook = $book.find(".book");
      $innerBook.show();
      return $innerBook.animate({
        right: "270px",
        opacity: 1.0
      }, 1000, "easeInOutQuart", __bind(function() {
        return this.bookMoveSecond();
      }, this));
    };
    JsBook.prototype.bookMoveSecond = function() {
      var $book, $innerBook;
      $book = $("#mainVisualBook" + this.id);
      $innerBook = $book.find(".book");
      return setTimeout(__bind(function() {
        return $innerBook.animate({
          right: "520px",
          opacity: 1.0
        }, 1000, "easeInOutQuart", __bind(function() {
          return this.rightBGMove();
        }, this));
      }, this), 1000);
    };
    JsBook.prototype.rightBGMove = function() {
      var $book, $rightbg;
      $book = $("#mainVisualBook" + this.id);
      $rightbg = $book.find(".rightbg");
      $rightbg.css({
        width: "320px",
        opacity: 0
      });
      $rightbg.show();
      return $rightbg.animate({
        width: "520px",
        opacity: 1.0
      }, 500, "easeInOutQuart", __bind(function() {
        this.textMove(1);
        setTimeout(__bind(function() {
          return this.textMove(2);
        }, this), 100);
        return setTimeout(__bind(function() {
          return this.textMove(3);
        }, this), 200);
      }, this));
    };
    JsBook.prototype.textMove = function(index) {
      var $book, $text;
      $book = $("#mainVisualBook" + this.id);
      $text = $book.find(".text" + index);
      $text.css({
        right: "-100px",
        opacity: 0
      });
      $text.show();
      return $text.animate({
        right: "0px",
        opacity: 1.0
      }, 1500, "easeInOutQuart");
    };
    return JsBook;
  })();
  SwfBook = (function() {
    __extends(SwfBook, Book);
    function SwfBook(book, id) {
      this.book = book;
      this.id = id;
      this.time = book.attr("time");
      this.swf = book.attr("swf");
      this.initField();
    }
    SwfBook.prototype.init = function() {
      var $book;
      $book = $("#mainVisualBook" + this.id);
      $book.show();
      return $book.append("<div id=\"mainVisualSWF" + this.id + "\"><p><a href=\"http://www.adobe.com/go/getflashplayer\"><img src=\"http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\" alt=\"Get Adobe Flash player\" /></a></p></div>");
    };
    SwfBook.prototype.play = function() {
      this.init();
      return swfobject.embedSWF(this.swf, "mainVisualSWF" + this.id, "750", "240", "9.0.0", "/js/flash/expressInstall.swf", {}, {
        wmode: "transparent"
      });
    };
    return SwfBook;
  })();
  Bookshelf = (function() {
    function Bookshelf(path) {
      this.books = [];
      this.xmlPath = path;
      this.currentIndex = 0;
      this.initField();
      this.gotoNext = null;
    }
    Bookshelf.prototype.initField = function() {
      return $("#eyecatch").html("<div id=\"mainVisualBookshelf\"></div><div id=\"mainVisualNavi\"></div>");
    };
    Bookshelf.prototype.loadXML = function() {
      return $.get(this.xmlPath, __bind(function(data) {
        return this.loaded(data);
      }, this));
    };
    Bookshelf.prototype.loaded = function(xml) {
      var $books, $xml;
      $xml = $(xml);
      $books = $xml.find("bookshelf > book");
      this.naviButton($books.length);
      $books.each(__bind(function(i) {
        var book;
        book = $books.eq(i);
        if (book.attr("swf") !== "") {
          return this.books.push(new SwfBook(book, i));
        } else {
          return this.books.push(new JsBook(book, i));
        }
      }, this));
      return this.setCurrentIndex(0);
    };
    Bookshelf.prototype.naviButton = function(size) {
      var $navi, i, naviHtml;
      $navi = $("#mainVisualNavi");
      i = 0;
      naviHtml = "";
      while (i < size) {
        naviHtml += "<div id=\"mainVisualNavi" + i + "\" class=\"mainVisualNavi\"><img src=\"/images/top/paginate_" + (i + 1) + ".png\" alt=\"\" /></div>";
        i++;
      }
      $navi.append(naviHtml);
      return this.naviButtonListenEvent();
    };
    Bookshelf.prototype.naviButtonListenEvent = function() {
      var $buttons;
      $buttons = $("#mainVisualNavi .mainVisualNavi");
      return $buttons.each(__bind(function(i) {
        var $button;
        $button = $buttons.eq(i);
        return $button.click(__bind(function() {
          if (i !== this.getCurrentIndex()) {
            return this.setCurrentIndex(i);
          }
        }, this));
      }, this));
    };
    Bookshelf.prototype.setCurrentIndex = function(index) {
      this.close(this.getCurrentIndex());
      this.play(index);
      this.changeCurrentNaviImage(index);
      return this.currentIndex = index;
    };
    Bookshelf.prototype.getCurrentIndex = function() {
      return this.currentIndex;
    };
    Bookshelf.prototype.play = function(index) {
      clearTimeout(this.gotoNext);
      this.gotoNext = setTimeout(__bind(function() {
        var next;
        next = index + 1;
        if (next + 1 > this.books.length) {
          next = 0;
        }
        return this.setCurrentIndex(next);
      }, this), this.books[index].time * 1000);
      return this.books[index].play();
    };
    Bookshelf.prototype.close = function(index) {
      return this.books[index].close();
    };
    Bookshelf.prototype.changeCurrentNaviImage = function(index) {
      var currentImg, currentNavi, currentSrc, indexImg, indexNavi, indexSrc;
      currentNavi = $(".mainVisualNavi.current");
      if (currentNavi.length > 0) {
        currentNavi.removeClass("current");
        currentImg = currentNavi.find("img");
        currentSrc = currentImg.attr("src");
        currentImg.attr("src", currentSrc.replace("_on.png", ".png"));
      }
      indexNavi = $("#mainVisualNavi" + index);
      indexNavi.addClass("current");
      indexImg = indexNavi.find("img");
      indexSrc = indexImg.attr("src");
      return indexImg.attr("src", indexSrc.replace(".png", "_on.png"));
    };
    return Bookshelf;
  })();
  $(document).ready(function() {
    var shelf;
    shelf = new Bookshelf("/images/main_visual/main_visual.xml");
    return setTimeout(function() {
      return shelf.loadXML();
    }, 500);
  });
}).call(this);

