// JavaScript Document
$(function() {
$(".pagetop").click(function() {
$('body,html').animate({scrollTop:0}, 500, 'swing');
return false;
});
$('a[href^=#]').on('click',function() {
// var mrg = 0;
// if($("body").css("background-size") == "cover"){
var mrg = $("#head").outerHeight() + 10;
//var mrg = $("#header #menu").outerHeight() + 10;
// }
var href= $(this).attr("href");
var target = $(href == "#" || href == "" ? 'html' : href);
var position = target.offset().top - mrg;
if($(this).hasClass("nomrg")){ position = 0; }
$('body,html').animate({scrollTop:position}, 500, 'swing');
return false;
});
$("#menu > ul > li:nth-child(5) > a").on("click", function() {
$(this).next().slideToggle();
});
$("#menu > ul > li:nth-child(5) > a").click(function(event){
event.preventDefault();
});
$("#shoplist ul#area li.cat-item-14,#shoplist ul#area li.cat-item-18").append('');
$(document).on('click','#shoplist ul#area li.cat-item-14 .svg-inline--fa',function(){
if(!$("#shoplist ul#area li.cat-item-14 > ul").hasClass("on")){
$("#shoplist ul#area li.cat-item-14 > ul").addClass("on");
}else{
$("#shoplist ul#area li.cat-item-14 > ul").removeClass("on");
}
});
$(document).on('click','#shoplist ul#area li.cat-item-18 .svg-inline--fa',function(){
if(!$("#shoplist ul#area li.cat-item-18 > ul").hasClass("on")){
$("#shoplist ul#area li.cat-item-18 > ul").addClass("on");
}else{
$("#shoplist ul#area li.cat-item-18 > ul").removeClass("on");
}
});
setsize();
imgchg();
setheight();
//本アップ対応
$("a.nolink").click(function(e) {
e.preventDefault;
return false;
});
});
$(window).load(function(){
setsize();
imgchg();
setheight();
movepos();
});
$(window).resize(function () {
setsize();
imgchg();
movepos();
});
$(window).scroll(function () {
setsize();
imgchg();
});
$(window).on('orientationchange', function(){
setsize();
imgchg();
});
function setsize(){
var hsize = $("#head").outerHeight();
var hm = $("#head #menu").outerHeight();
var hs = hsize - hm - 40;
var state = $("#header").css("background-size");
var scl = $('body').scrollTop();
if(scl==0){scl = $('html').scrollTop();}
if(state == 'contain'){
if(scl >= hs) {
$("#container").css("padding-top",hsize+"px");
$("#header > p").css("top","-40px");
$("#header #logo img").css({'height':'30px','bottom':'-43px'});
//$("#head").css({'position':'fixed','top':'-'+hs+'px'});
$("#head").css({'position':'fixed','top':'-'+($("#head").outerHeight() - hm - 40)+'px'});
}else{
$("#head").css({'position':'relative','top':0});
$("#container").removeAttr('style');
$("#header > p").removeAttr("style");
$("#header #logo img").removeAttr("style");
}
}else{
$("#head").removeAttr('style');
$("#container").css("padding-top",hsize+"px");
$("#header > p").removeAttr("style");
$("#header #logo img").removeAttr("style");
}
/*
$("#container").css("padding-top",hsize+"px");
console.log();
var hsize = $("#header").outerHeight();
$("body").css("padding-top",hsize+"px");
var msize = $("#header #menu").outerHeight();
var hm = hsize - msize - 20;
var scl = $('body').scrollTop();
if(scl==0){scl = $('html').scrollTop();}
var state = $("#header").css("background-size");
if(state == 'contain'){
if(scl <= hm) {
$("body > header").css('top','-'+scl+'px');
}else{
$("body > header").css('top','-'+hm+'px');
}
}else{
$("body > header").removeAttr('style');
}
*/
}
function setheight(){
//if($('.contents.recruit.detail ul.voice li h4 span').css('display') != 'block'){
$('.contents.recruit.detail ul.voice li dl dd').matchHeight();
$('#column div.contents li div.text').matchHeight();
$('ul#news li .text').matchHeight();
$('ul#news li a .img').matchHeight();
$('#menulist .contents li div.text').matchHeight();
$('#newmenu .contents li div.text').matchHeight();
$('#menus li div.text').matchHeight();
//}
}
//他ページよりのアンカーリンク
function movepos(){
//var mrg = 0;
//if($("body").css("background-size") == "cover"){
var mrg = $("#header").outerHeight() + 10;
//var mrg = $("#header #menu").outerHeight() + 10;
//}
var href = location.href;
if(href.indexOf("#")>=0 || location.search){
var hrefs=href.substring(href.indexOf("#")+1,href.length);
href = hrefs;
if( location.search || hrefs.indexOf("/menu/page/")>=0 || hrefs.indexOf("/area1/page/")>=0 || hrefs.indexOf("/area2/page/")>=0 ){ href = 'menus'; }
if(hrefs.indexOf("link=searchmenu")>=0 ){ href = 'searchmenu'; }
if(href.indexOf("?")>=0){
var parm = href.split('?');
href = parm[0];
}
var position = $("#"+href).offset().top;
var speed = 500;
$('body,html').animate({scrollTop:position-mrg}, speed, 'swing');
//return false;
}else{
return false;
}
//var position = $("#"+href).offset().top;
// var speed = 500;
// $('body,html').animate({scrollTop:position-mrg}, speed, 'swing');
var hashString = location.hash.substr(1); // remove '#'
history.replaceState('', document.title, window.location.pathname);
//return false;
}
function imgchg(){
var $el_480 = $('.imgchg_480');
var $el_768 = $('.imgchg_768');
var sp = '_sp.';
var tb = '_tb.';
var pc = '_pc.';
var state = $("#header").css("background-size");
//768以下
$el_768.each(function() {
var $this = $(this);
var $repstr = $this.attr('src');
var $rep = pc;
if ( $repstr.indexOf(pc) != -1) { $rep = pc; }
if ( $repstr.indexOf(tb) != -1) { $rep = tb; }
if ( $repstr.indexOf(sp) != -1) { $rep = sp; }
if(state == 'cover' && $rep != tb){
$this.attr('src', $this.attr('src').replace($rep, tb));
}
if(state == 'contain' && $rep != sp){
$this.attr('src', $this.attr('src').replace($rep, sp));
}
if(state != 'cover' && state != 'contain' && $rep != pc){
$this.attr('src', $this.attr('src').replace($rep, pc));
}
//if ( str.indexOf('hoge') != -1) {
});
//480以下
$el_480.each(function() {
var $this = $(this);
if(state == 'contain'){
$this.attr('src', $this.attr('src').replace(pc, sp));
} else {
$this.attr('src', $this.attr('src').replace(sp, pc));
}
});
}