var httpUtils = require("HttpUtils");
cc.Class({
  extends: require("Base"),

  properties: {
    pageview: {
      default: null,
      type: cc.PageView
    },
    btn_1: {
      default: null,
      type: cc.Sprite
    },
    btn_2: {
      default: null,
      type: cc.Sprite
    },
    btn_3: {
      default: null,
      type: cc.Sprite
    },
    btn_4: {
      default: null,
      type: cc.Sprite
    },
    btn_5: {
      default: null,
      type: cc.Sprite
    }
  },

  // LIFE-CYCLE CALLBACKS:

  onLoad() {
    this.initBtn();
    this.initView();
  },

  start() {},

  update(dt) {},

  initView: function() {
    var self = this;
    setViewTouch(
      this.btn_1,
      function(event) {
        this.pageview.setCurrentPageIndex(0);
        this.initBtn();
      },
      null,
      null,
      this
    );
    setViewTouch(
      this.btn_2,
      function(event) {
        this.pageview.setCurrentPageIndex(1);
        this.initBtn();
      },
      null,
      null,
      this
    );
    setViewTouch(
      this.btn_3,
      function(event) {
        this.pageview.setCurrentPageIndex(2);
        this.initBtn();
      },
      null,
      null,
      this
    );
    setViewTouch(
      this.btn_4,
      function(event) {
        this.pageview.setCurrentPageIndex(3);
        this.initBtn();
      },
      null,
      null,
      this
    );
    setViewTouch(
      this.btn_5,
      function(event) {
        this.pageview.setCurrentPageIndex(4);
        this.initBtn();
      },
      null,
      null,
      this
    );
  },
  initBtn: function() {
    var self = this;
    self.btn_1.spriteFrame = new cc.SpriteFrame(
      cc.url.raw("resources/tabdemo/学习指南2.png")
    );
    self.btn_2.spriteFrame = new cc.SpriteFrame(
      cc.url.raw("resources/tabdemo/看一看2.png")
    );
    self.btn_3.spriteFrame = new cc.SpriteFrame(
      cc.url.raw("resources/tabdemo/动一动2.png")
    );
    self.btn_4.spriteFrame = new cc.SpriteFrame(
      cc.url.raw("resources/tabdemo/读一读2.png")
    );
    self.btn_5.spriteFrame = new cc.SpriteFrame(
      cc.url.raw("resources/tabdemo/写一写2.png")
    );
    var index = this.pageview.getCurrentPageIndex();

    switch (index) {
      case 0:
        self.btn_1.spriteFrame = new cc.SpriteFrame(
          cc.url.raw("resources/tabdemo/学习指南1.png")
        );
        break;
      case 1:
        self.btn_2.spriteFrame = new cc.SpriteFrame(
          cc.url.raw("resources/tabdemo/看一看1.png")
        );
        break;
      case 2:
        self.btn_3.spriteFrame = new cc.SpriteFrame(
          cc.url.raw("resources/tabdemo/动一动1.png")
        );
        break;
      case 3:
        self.btn_4.spriteFrame = new cc.SpriteFrame(
          cc.url.raw("resources/tabdemo/读一读1.png")
        );
        break;
      case 4:
        self.btn_5.spriteFrame = new cc.SpriteFrame(
          cc.url.raw("resources/tabdemo/写一写1.png")
        );
        break;
    }
  }
});
