

jQuery(function($) {
new function() {

    jbr = {

      pos: 0,
      header_scrolled: false,
      bg_pos: 0,
      bg_stat: false,
      direction: '',


        //  json_get {{{
        json_get: function(uri, _async) {
            var defer = $.Deferred();
            _async = _async === undefined ? true : _async;
            $.ajax({
                async: _async,
                url: uri,
                cache: false,
                data: {
                },
                type: 'get',
                dataType: 'json',
                success: defer.resolve,
                error: defer.reject
            });
            return defer.promise();
        },
        // }}}
        // xml_get {{{
        xml_get: function(uri, _async) {
            var defer = $.Deferred();
            _async = _async === undefined ? true : _async;
            $.ajax({
                async: _async,
                url: uri,
                cache: false,
                data: {
                },
                type: 'get',
                dataType: 'xml',
                success: defer.resolve,
                error: defer.reject
            });
            return defer.promise();
        },
        // }}}
        // html_get {{{
        html_get: function(uri, _async) {
            var defer = $.Deferred();
            _async = _async === undefined ? true : _async;
            $.ajax({
                async: _async,
                url: uri,
                cache: false,
                data: {
                },
                type: 'get',
                dataType: 'html',
                success: defer.resolve,
                error: defer.reject
            });
            return defer.promise();
        },
        // }}}

        // swap_sp {{{
        swap_sp: function() {
            $("img").each(function() {
                var elem = $(this);
                if ($(this).hasClass("swap-sp2")) {
                    jbr._swap_sp2(elem);
                } else if (elem.hasClass("swap-sp3")) {
                    jbr._swap_sp3(elem);
                }
            });
        },
        // }}}
        // _swap_sp2 {{{
        // xxxx.ext <=> xxxx_sp.ext
        //
        _swap_sp2: function(elem) {
            var imgsrc = elem.attr('src');
            if (typeof imgsrc === 'undefined') {
                return;
            }
            var tmp = imgsrc.split(/\//);
            var filename = tmp.pop();
            var path = tmp.join('/');
            var tmp2 = filename.split(/\./);
            var fname = tmp2[0];
            var ext = tmp2[1];
            if (cmn.view == 'sp') {
                if (!fname.match(/_sp$/)) {
                    //console.log(path);
                    elem.attr('src', path + '/' + fname + '_sp.' + ext);
                }
            } else {
                if (fname.match(/_sp$/)) {
                    var _pcimg = fname.replace(/_sp/, '');
                    elem.attr('src', imgsrc.replace(new RegExp(fname), _pcimg));
                }
            }
        },
        // }}}
        // _swap_sp3 {{{
        // xxxx_pc.ext <=> xxxx_sp.ext
        //
        _swap_sp3: function(elem) {
            var imgsrc = elem.attr('src');
            var tmp = imgsrc.split(/\//);
            var filename = tmp.pop();
            var path = tmp.join('/');
            var tmp2 = filename.split(/\./);
            var fname = tmp2[0];
            var ext = tmp2[1];
            if (cmn.view == 'sp') {
                if (!fname.match(/_sp$/)) {
                    elem.attr('src', path + '/' + fname.replace(/_pc/,'_sp') + '.' + ext);
                }
            } else {
                if (fname.match(/_sp$/)) {
                    elem.attr('src', path + '/' + fname.replace(/_sp/,'_pc') + '.' + ext);
                }
            }
        },
        // }}}

        // init {{{
        init: function() {
          jbr.sp_menu();
          jbr.faq();
          jbr.swap_sp();
          jbr.scroll_to();
          jbr.archive_hover();
          jbr.button_hover();
        },
        // }}}
        // load_init {{{
        load_init: function() {
          jbr.top_animation();
        },
        // }}}
        // scroll_proc {{{
        scroll_proc: function() {
          var pos = $(window).scrollTop();
          if (pos > jbr.pos) {
            jbr.direction = 'down';
          } else {
            jbr.direction = 'up';
          }
          jbr.pos = pos;

          jbr.solution_bg();
        },
        // }}}

      //header_class {{{
      header_class: function() {
        var pos = $(window).scrollTop();
        if (pos > 0 && jbr.header_scrolled == false) {
          jbr.header_scrolled = true;
          $(".header").addClass("-scrolled");
          $(".header__inner").addClass("-scrolled");
          $(".header__regist--wrap").addClass("-scrolled");
          $(".header__logo--image").addClass("-scrolled");
          if ($(".header__logo--image.-business").length > 0 && $(".header__logo--image.-entry").length <= 0 ) {
            $(".header__logo--image.-business").attr('src', $(".header__logo--image.-business").attr('src').replace(/_wh\.png/, '.png'));
          }
        } else if (pos <= 0 && jbr.header_scrolled == true) {
          jbr.header_scrolled = false;
          $(".header").removeClass("-scrolled");
          $(".header__inner").removeClass("-scrolled");
          $(".header__regist--wrap").removeClass("-scrolled");
          $(".header__logo--image").removeClass("-scrolled");
          if ($(".header__logo--image.-business").length > 0 && $(".header__logo--image.-entry").length <= 0 ) {
            $(".header__logo--image.-business").attr('src', $(".header__logo--image.-business").attr('src').replace(/\.png/, '_wh.png'));
          }
        }
      },
      // }}}
      // sp_menu {{{
      sp_menu: function() {
        var html = $(".header .menu-wrap").html();
        $(".header .sp-menu__inner").prepend(html);

        $("[data-menu-button]").on('click', function() {
          if ($(".sp-menu").hasClass('-opened')) {
            // close
            $(".sp-menu").removeClass("-opened");
            $(".menu-btn .menu-btn__image").attr('src', $(".menu-btn .menu-btn__image").attr('src').replace(/_close/, ''));
          } else {
            // open
            $(".sp-menu").addClass('-opened');
            $(".menu-btn .menu-btn__image").attr('src', $(".menu-btn .menu-btn__image").attr('src').replace(/menu\.svg/, 'menu_close.svg'));
          }
        });
      },
      // }}}
      // faq {{{
      faq: function() {
        $(".faq-list__q").on('click', function() {
          var elem = $(this);
          if ($(this).hasClass("-opened")) {
            // close
            elem.next(".faq-list__a").slideUp(300, function() {
              elem.removeClass("-opened");
            });
          } else {
            // open
            elem.next(".faq-list__a").slideDown(300, function() {
              elem.addClass("-opened");
            });
          }
        });
      },
      // }}}
 
      // top_animation {{{
      top_animation: function() {
        $(".mv__inner").addClass('-anime');

        // 座標位置取得
        if ($(".top2").length > 0 && $(".solution").length > 0) {
          jbr.bg_pos = $(".solution").offset().top;
        }

      },
      // }}}
      // solution_bg {{{
      solution_bg: function() {
        if ($(".top2").length > 0 && $(".solution").length > 0) {
          if (jbr.pos > (jbr.bg_pos - (cmn.bh / 3 * 1))) {
            if (jbr.bg_stat == false && jbr.direction == 'down') {
              //console.log("bg_stat true");
              jbr.bg_stat = true;
              jbr.solution_spread();
            }
          }
          if (jbr.pos <= (jbr.bg_pos - (cmn.bh / 3 * 1))) {
            if (jbr.bg_stat == true && jbr.direction == 'up') {
              //console.log("bg_stat false");
              jbr.bg_stat = false;
              jbr.solution_shrink();
            }
          }
        }
      },
      // }}}
      // solution_spread {{{
      solution_spread: function() {
        //$(".solution__inner").addClass("-spread");
        $(".solution__ttl").addClass("-anime");
      },
      // }}}
      // solution_shrink {{{
      solution_shrink: function() {
        //$(".solution__inner").removeClass("-spread");
        $(".solution__ttl").removeClass("-anime");
      },
      // }}}
      // data_scroll_to {{{
      data_scroll_to: function() {
          $(document).on('click', "[data-scroll-to]", function() {
              var _id = $(this).attr('data-scroll-to');
              var _offset = $(this).attr('data-scroll-offset');
              if (typeof _id !== "undefined" && $("#" + _id).length > 0) {
                  jbr.scroll_to(_id, _offset);
              }
          });
      },
      // }}}
      //scroll_to {{{
      scroll_to: function(toid, offset) {
          if ($("#" + toid).length > 0) {

          var _offset = offset === undefined ? 40 : offset;

          var pos = $("#" + toid).offset().top;
          var header_h = $(document).find("header").height();
          if (typeof header_h !== 'undefined') {
              pos = pos - header_h - _offset;
          }
          if ($(".anchor-80").length > 0) {
              pos = pos - 80;
          }

          $('body, html').animate({
            scrollTop: pos
          }, 1000, 'ease-out');

          }
      },
      // }}}
      // archive_hover {{{
      archive_hover: function() {
        $(".archive__box a").on('mouseover', function() {
          $(this).find("img").addClass("-zoom");
          $(this).find(".archive__post--ttl").addClass("-hover");
        });
        $(".archive__box a").on('mouseout', function() {
          $(this).find("img").removeClass("-zoom");
          $(this).find(".archive__post--ttl").removeClass("-hover");
        });
        $(".archive__box .archive__post--image").on('mouseover', function() {
          $(this).parent("a").find(".archive__post--ttl").addClass("-hover");
        });
        $(".archive__box .archive__post--image").on('mouseout', function() {
          $(this).parent("a").find(".archive__post--ttl").removeClass("-hover");
        });

        // top
        $(".story-list__link").on('mouseover', function() {
          $(this).find("img").addClass("-zoom");
          $(this).find(".story-list__ttl").addClass("-hover");
        });
        $(".story-list__link").on('mouseout', function() {
          $(this).find("img").removeClass("-zoom");
          $(this).find(".story-list__ttl").removeClass("-hover");
        });

        $(".recommend-list__link").on('mouseover', function() {
          $(this).find("img").addClass("-zoom");
          $(this).find(".recommend-list__ttl").addClass("-hover");
        });
        $(".recommend-list__link").on('mouseout', function() {
          $(this).find("img").removeClass("-zoom");
          $(this).find(".recommend-list__ttl").removeClass("-hover");
        });

        $(".column-list__link").on('mouseover', function() {
          $(this).find("img").addClass("-zoom");
          $(this).find(".column-list__ttl").addClass("-hover");
        });
        $(".column-list__link").on('mouseout', function() {
          $(this).find("img").removeClass("-zoom");
          $(this).find(".column-list__ttl").removeClass("-hover");
        });
      },
      // }}}
      // button_hover {{{
      button_hover: function() {
        $(".-btn-orange, .-btn-white").on('mouseover', function() {
          $(this).find(".btn-text").addClass("mouse_hover");
        });
        $(".-btn-orange, .-btn-white").on('mouseout', function() {
          $(this).find(".btn-text").removeClass("mouse_hover");
        });
      },
      // }}}

      _dummy: function() {
      }
    }
}
});

jQuery(function($) {
$(function() {

    jbr.init();


});
});


jQuery(function($) {
$(window).on('load', function() {
    jbr.load_init();
});
});

jQuery(function($) {
$(window).on('scroll', function() {

  jbr.header_class();
  jbr.scroll_proc();

});
});

jQuery(function($) {
$(window).on('resize', function() {
    if (cmn.timer !== false) {
        clearTimeout(cmn.timer);
    }
    cmn.timer = setTimeout(function() {

        cmn.getsize();
        cmn.getview();
        jbr.swap_sp();

    },cmn.resize_delay);
});
});

// vim: set foldmethod=marker :
