﻿//
$(function () {
    // 100％背景
    $(document).ready(function () {
        var wH = $(window).height();
        var divH = $('#home_header').innerHeight();
        if (wH > divH) {
            if ($("#view_photo").val() == "on") {
                $('#home_header').css('height', wH + 'px');
            }
            else {
                $('#home_header').css('height','20px');
            }
        }
    });

    // IE用オブジェクトフィット
    objectFitImages('.ofi');

    // モーダル
    $('.modal').click(function () {
    }).magnificPopup({
        type: 'inline',
        preloader: false,
        overflowY: 'scroll'
    });

    //ページトップ
    var topBtn = $('#pagetop');
    topBtn.hide();
    $(window).scroll(function () {
        if ($(this).scrollTop() > 300) {
            topBtn.fadeIn();
        } else {
            topBtn.fadeOut();
        }
    });
    topBtn.click(function () {
        $('body,html').animate({
            scrollTop: 0
        }, 500);
        return false;
    });

    //page topボタン Footerで止まるように
    $(window).scroll(function (e) {
        var bottomY = 20,
            $window = $(e.currentTarget),
            height = $window.height(),
            scrollTop = $window.scrollTop(),
            documentHeight = $(document).height(),
            footerHeight = $("footer").height();
        bottomHeight = footerHeight + height + scrollTop + bottomY - documentHeight;

        if (scrollTop >= documentHeight - height - footerHeight + bottomY) {
            $('#pagetop').css({ bottom: bottomHeight - bottomY });
        } else {
            $('#pagetop').css({ bottom: bottomY });
        };

        //top_barにシャドウ追加
        if (scrollTop > 1) {
            $('#top_bar').addClass("follow");
        } else {
            $('#top_bar').removeClass("follow");
        };
    });

    // ↓スクロール
    $('a[href^="#concept"]').click(function () {
        var speed = 300;
        var href = $(this).attr("href");
        var target = $(href == "#" || href == "" ? 'html' : href);
        var position = target.offset().top - $("#top_bar").height() * 2;;
        $("html, body").animate({ scrollTop: position }, speed, "swing");
        return false;
    });
    $('a[href^="#access"]').click(function () {
        var speed = 300;
        var href = $(this).attr("href");
        var target = $(href == "#" || href == "" ? 'html' : href);
        var position = target.offset().top - $("#top_bar").height() * 2;;
        $("html, body").animate({ scrollTop: position }, speed, "swing");
        return false;
    });
});

//windows幅を固定
//※モーダルが開いた時背景がぼよーんとなるのでHTMLとfixの要素固定
var ua = navigator.userAgent;
$(window).on('load resize', function () {
    if (ua.indexOf('iPhone') == -1 && ua.indexOf('Android') == -1 && ua.indexOf('Mobile') -1) {
        window_base = window.innerWidth;
        var w_width = $(window).width();
        $("html").width(w_width);
        $("#top_bar").width(w_width);
        $("#pagetop").width(w_width);

    }
    var window_w = $(window).width();
    if (window_w > 480 && ua.indexOf('iPhone') == -1 && ua.indexOf('Android') == -1 && ua.indexOf('Mobile') - 1) {
        if ($(".bg_body").hasClass("pc") == false)
            $(".bg_body").addClass("pc").removeClass("sp");
    }
    else {
        if ($(".bg_body").hasClass("sp") == false)
            $(".bg_body").addClass("sp").removeClass("pc");
    }
});
//function