$(function() {
    var _w = $(window).width();
    /* event file */
    const $loadpath = 'event.php?shopid=';

    const $area = $('.area-navi').find('li');
    /* shop list */
    const $slist = $('.shoplist').find('li');
    /* init shop list: kanto*/
    const $initarea = $('.shoplist').find('.kanto');

    $initarea.each(function() {
        $(this).removeClass('hide');
    });
    /* load init shop info */
    let $initlist = $initarea.eq(0);
    let initloadid = $initlist .data('id');

    $('.area-navi').find('.kanto').addClass('on');
    if(_w > 767){
        $initlist .addClass('on');
    };

    var loaderFunc = function(loadpage,$sid) {
        _w = $(window).width();
        $.ajax({
            url: loadpage,
            scriptCharset: 'utf-8',
            dataType: 'html',
            cache: false,
            type: 'GET',
            beforeSend: function(html) {
                $('#shopeventinfo').html('').addClass('loading').removeClass('loaded');//for pc
                $('#shopinfo'+$sid).addClass('loading');//for sp
                $('.loadshopinfo').html('').removeClass('loaded');//for sp
            }
        }).done(function(html) {
            if(_w > 767){
                $('#shopeventinfo').html(html);//for pc
            }else{
                $('#shopinfo'+$sid).html(html);//for sp
            }
        }).fail(function(html) {
            if(_w > 767){
                $('#shopeventinfo').html('<div class="inner error-pc"><p class="error">error</p></div>');//for pc
            }else{
                $('#shopinfo'+$sid).html('<div class="inner error-sp"><p class="error">error</p></div>');//for sp
            }
        }).always(function(html) {
            setTimeout(function(){
                $('#shopeventinfo').removeClass('loading').addClass('loaded');
                $('#shopinfo'+$sid).removeClass('loading').addClass('loaded');
            },300);
        });
    }
    loaderFunc($loadpath+initloadid);

    /* shop list event*/
    $area.on('click', function() {
        $area.removeClass('on');
        $(this).addClass('on');
        $slist.addClass('hide');
        //remove shopinfo for sp//
        $('.loadshopinfo').html('');
        var thisarea = $(this).data('area');
        if (thisarea == 'all') {
            $slist.removeClass('hide');
        } else {
            $('.shoplist').find('.' + thisarea).each(function() {
                $(this).removeClass('hide');
            })
        }
    });
    $slist.on('click', function(event) {
        event.stopPropagation();
        $slist.removeClass('on');
        _this = $(this);
        _this.addClass('on');
        let $sid = _this.data('id');
        let loadpath = $loadpath+$sid;
        loaderFunc(loadpath,$sid);
        if(_w > 767){
            setTimeout(function(){
                let thispos = $('#event').offset().top;
                $('html, body').animate({scrollTop:thispos},300);
            },500);
        }else{
            setTimeout(function(){
                let thispos = _this.offset().top;
                $('html, body').animate({scrollTop:thispos},300);
            },500);
        }
        
        return false;
    });

    $(window).on('resize',function(){
        if(_w < 767){
            $slist.removeClass('on');
        }
    });

    /* load instagram */
    const $get_insta = './insta/get_instagram.php';
    const $insta_list = $('#insta-list');
    $.ajax({
        url: $get_insta,
        scriptCharset: 'utf-8',
        dataType: 'html',
        cache: false,
        type: 'GET',
        beforeSend: function(html) {
            $insta_list.addClass('loading');
        }
    }).done(function(html) {
        $insta_list.append(html);
    }).fail(function(html) {
        $insta_list.append('<li><p class="error">error</p></li>');
    }).always(function(html) {
        setTimeout(function(){
            $insta_list.removeClass('loading').addClass('loaded');
        },300);
    });

});

