// D => [14811]IE時にjs非同期だとスライダーが動作しないためbxslider.jsに移動
//$(function() {
//	/**
//	* 目玉商品、ランキング、最近見た商品用　標準bxslider
//	*
//	*/
//	$('.rmd_slider').bxSlider({
//		slideWidth: 178,
//		minSlides: 5,
//		maxSlides: 5,
//		startSlide: 0,
//		slideMargin: 20,
//		adaptiveHeight: true,
//		adaptiveHeightSpeed: 500,
// [7836]暫定対応、Chrome73にバージョンアップされるとbxSliderのリンクが効かなくなる
// D => [14961]デフォルトのぺージャーが消える
//		touchEnabled: false
// ベースデザイン変更に伴い追加したが不要なため削除
//		touchEnabled: false,
//		controls: true,
//		nextSelector:'.next-btn',
//		prevSelector:'.prev-btn'
// D <= [14961]デフォルトのぺージャーが消える
//	});
//});
// D <= [14811]IE時にjs非同期だとスライダーが動作しないためbxslider.jsに移動

// サイドバーカテゴリアコーディオン
$(function(){
    $(".ul_tree .toggle").click(function() {
			$(this).parents('li').toggleClass("active").children("ul").slideToggle();
    });
    
    $(".ul_tree_tq .toggle_tq").click(function() {
			$(this).parents('li').toggleClass("active").children("ul").slideToggle(0);
    });

});

/*
* 三点リーダー
* 
*/
$(function() {
	$('.rmd_slider_wide .productContents h3 a').addClass('addEllipsis');
});

function addEllipsis(name){
  $(name).each(function() {
    var $target = $(this);
    var html = $target.html();
    var $clone = $target.clone();
    $clone
    .css({
      display: 'none',
      position : 'absolute',
      overflow : 'visible'
    })
    .width($target.width())
    .height('auto');
    $target.after($clone);
    while((html.length > 0) && ($clone.height() > $target.height())) {
      html = html.substr(0, html.length - 1);
      $clone.html(html + '...');
    }
    $target.html($clone.html());
    $clone.remove();
  });
}

$(window).on('load', function(){
	addEllipsis('.addEllipsis');
	let slider_height = $('.rmd_slider_wide').outerHeight();
	$('.rmd_slider_wide').parent('.bx-viewport').outerHeight(slider_height);
});

// DOMにlocalStorage用のhidden項目生成
$(function(){
	// 必要formタグの後ろにhidden項目設定
	$("<input>", {
		type: 'hidden',
		id: 'favorites_ls',
		name: 'favorites_ls',
		value: localStorage.getItem('raku2_favorites')
// 検索時にお気に入り情報を付与するとGETパラメータ過多の可能性があるため取り下げ
//	}).appendTo('#login_mypage, #header_login_form, #search_form');
	}).appendTo('#login_mypage, #header_login_form');

	$("<input>", {
		type: 'hidden',
		id: 'favorites_del_ls',
		name: 'favorites_del_ls',
		value: localStorage.getItem('raku2_favorites_del')
// 検索時にお気に入り情報を付与するとGETパラメータ過多の可能性があるため取り下げ
//	}).appendTo('#login_mypage, #header_login_form, #search_form');
	}).appendTo('#login_mypage, #header_login_form');
});

// aタグのformをsubmitする
function fnFavoriteSubmit(form, action) {

	// LocalStorageからformのhidden項目にvalue再設定
	$('#favorites_ls').val(localStorage.getItem('raku2_favorites'));
	$('#favorites_del_ls').val(localStorage.getItem('raku2_favorites_del'));

	eccube.changeAction(action, form);
	document.forms[form].submit();
}

//絞り込み開閉用
$(function() {
// 高さ調節不要
//	$('.open-box').each(function(){
//		$(this).css("height",$(this).height()+"px");
//	});
	$('.open-box').hide();
	$('.btn-box').click(function () {
		$('.open-box').slideToggle();
		$(this).toggleClass('active');
	});
});

// 表示順変更用
$(function(){
	function fixPlaceHolderWidth(event, ui) {
		// adjust placeholder td width to original td width
		ui.children().each(function() {
			$(this).width($(this).width());
		});
		return ui;
	};

	$('.sortable, .sortable_mf').sortable({
		items: "tbody tr",
		cancel:".no_drag",
		handle:".updown",
		placeholder: 'ui-state-highlight',
		start: function(event, ui){
			ui.placeholder.height(ui.helper.outerHeight());
		},
		helper: fixPlaceHolderWidth,
		update: function(e, ui) {
			// ランク保存ボタン表示
			$('.btn-area-rank').show();
		}
	});
});