$(function(){
    var init = function() {
      var ht = $(window).outerHeight() - 130;
      $('.toc').height(ht);
      $('.content').height(ht);
    };
    init();
  var pagination = {
    getMJQuery: function() {
      if(!this.mJQuery) {
		this.mJQuery = self.parent.frames['toc'].window.jQuery;
      }
      return this.mJQuery;
    },
    menus: ['itemFront_1','itemFront_2','itemFront_3','itemFront_4','itemFront_5','item01','item01_1','item01_2','item01_3','item01_4','item01_5','item01_5_1','item01_5_2','item01_6','item02','item02_1','item02_2','item02_3','item02_4','item02_5','item02_5_1','item02_5_2','item03','item03_1','item03_1_1','item03_1_2','item03_1_3','item03_2','item04','item04_1','item04_2','item04_2_1','item04_2_2','item05','item05_1','item05_2','item05_2_1','item05_3','item05_4','item06','item06_1','item06_1_1','item06_1_2','item06_1_3','item06_2','item06_2_1','item06_2_2','item06_3','item06_3_1','item06_3_2','item06_4','item06_4_1','item06_4_2','item07','item07_1','item07_1_1','item07_1_2','item07_1_3','item07_1_4','item07_1_5','item07_1_6','item08','item08_1','item08_2','item08_3','item08_4','item08_5','item09','item09_1','item09_1_1','item09_1_2','item09_2','item09_2_1','item09_2_2','item09_2_3','item09_3','item10','item10_1','item10_1_1','item10_1_2','item10_1_3','item10_1_4','item10_1_5','item10_2','item10_2_1','item10_2_2','item10_2_3','item10_2_4','item10_3','item10_3_1','item10_3_2','item11','item11_1','item11_2','item11_3','item11_3_1','item11_3_2','item11_3_3','item11_4','item11_5','item11_6','item11_6_1','item11_6_2','item11_6_3','item11_6_4','item12','item12_1','item12_2','item12_2_1','item12_2_2','item12_2_3','item13','item13_1','item13_2','item13_3','item13_3_1','item13_3_2','item14','item14_1','item14_2','item14_3','item14_4','item14_5','item14_6','item14_7','item15'],
    currentIndex: 0,
    setCurrent: function(id) {
      var mJQuery = this.getMJQuery(),
        item = mJQuery('#' + id);
      mJQuery('.current').removeClass('current');
      item.addClass('current');
      for(var i = 0; i < this.menus.length; i++) {
        if(id === this.menus[i]) {
          this.currentIndex = i;
          return;
        }
      }
    },
    expand: function(current) {
      var flag = current.parent().parent().parent('ul');
      while(flag && flag.is(':hidden')) {
        flag.parents('li').attr('class', 'collapsable')
        flag.parents('li').children('div').attr('class', 'hitarea collapsable-hitarea');
        flag.show();
        flag = flag.parent().parent('ul');
      }
    },
    rollNext: function() {
	  if (this.currentIndex == this.menus.length-1){
		return;
	  }
      var mJQuery = this.getMJQuery(),
      item = mJQuery('#' + this.menus[this.currentIndex>=this.menus.length-1 ? 0 : ++this.currentIndex]);
      this.expand(item);
      this.setCurrent(item.attr('id'));
	  self.parent.frames['content'].window.location = item.attr('href');
    },
    rollPre: function() {
	  if (this.currentIndex <= 0){
		return;
	  }
      var mJQuery =  this.getMJQuery(),
      item = mJQuery('#' + this.menus[this.currentIndex <= 0 ? this.menus.length - 1 : --this.currentIndex]);
      this.expand(item);
      this.setCurrent(item.attr('id'));
	  self.parent.frames['content'].window.location = item.attr('href');
    },
    setEvent: function() {
      var self = this, mJQuery =  self.getMJQuery();
      mJQuery('.file a').click(function(e) {
        self.setCurrent($(this).attr('id'));
      });
      mJQuery('.folder a').click(function(e) {
        self.setCurrent($(this).attr('id'));
      });
    }
  };
  $('.up').click(function(e){
    e.preventDefault();
    pagination.rollPre();
  });
  $('.down').click(function(e){
    e.preventDefault();
    pagination.rollNext();
  });  
  $('.logo, .home').click(function(e){
    pagination.currentIndex = -1;
  });
  setTimeout(function(){pagination.setEvent(); }, 1000);
  window.pagination = pagination;
});
