/*!
 * main.js
 *
 */

(function($){ //start jquery

/**
 * common hover scripts
 *
 * set $.fn.mk_hoverSwap
 * set $.fn.mk_hoverLight
 * set $.fn.mk_hoverBlink
 *
 * マウスオーバー関係のスクリプト共通設定
 *
 * @requier: jquery.js, jquery.mk_hover.js
 */


$(function(){
	$('img.js-hoverSwap, input[type="image"].js-hoverSwap').mk_hoverSwap();
	$('img.js-hoverLight, input[type="image"].js-hoverLight').mk_hoverLight();
	$('img.js-hoverBlink, input[type="image"].js-hoverBlink').not('#siteNavi p.about img').mk_hoverBlink({
		speed: 600
	});
	
	$('.prt-tab ul.tabMenuC li:not(li:has(a.current))').mk_hoverLight();
	$('.prt-tab ul.tabMenuB li:not(li:has(a.current))').mk_hoverLight();
});



/**
 * リンク範囲設定
 * - .prt-itemList
 * - .prt-itemSlider
 * - .prt-rankingListA
 * - みんなのボイスなう！
 * @require: jquery.js, jquery.biggerlink.js, jquery.mk_hover.js
 * @modify : 2011-08-11 - oosugi@skillpartners.co.jp
 */

$(function(){
	// prt-itemList
	$('.prt-itemList li,\
	   .prt-itemSlider .itemList li, .prt-coordinateList li p.image')
		// リンク範囲を広げる
		.biggerlink({
			biggerclass:'js-bl-bigger', 	// class added to the first contained link and others that trigger it
			hoverclass:'js-bl-hover', 		// class added to parent element on hover/focus
			hoverclass2:'js-bl-hover2', 	// class added to parent element on hover/focus of other links
			clickableclass:'js-bl-hot' 	// class added to parent element with behaviour
		})
		// hoverでBlink
		.mk_hoverBlink({ speed: 600 });
	
	// prt-rankingListA
	// アプリマターなのでコメントアウト
	/*
	$('.prt-rankingListA li').each(function(){
		var $this = $(this);
		var href = $this.find('p.brand a').attr('href');
		var $img = $this.find('p.image img');
		$img.wrap('<a href="' + href + '"></a>');
	});
	*/

  createLinkAreaOnUserVoice();
	
	//みんなのボイスなう！のオーバー用画像先読み
	(new Image).src = '/img/parts/voice_bg_02_btm_on.png';
	(new Image).src = '/img/parts/voice_bg_02_on.png';
	(new Image).src = '/img/parts/voice_bg_02_top_on.png';
	(new Image).src = '/img/parts/voice_bg_03_on.png';
	
});


/**
 * set $.fn.flatHeights - 高さ揃え設定
 * - .prt-itemList
 * - .prt-itemListC
 * - .prt-itemListD
 * - .prt-itemListE
 *
 * @require: jquery.js, flatHeights.paddingbugfix-ver.js
 */

$(window).load(function(){
	$('.prt-tab ul.tabMenuB').flatHeightsAction('.tabBInner', 2);
	$('.prt-tab ul.tabMenuC').flatHeightsAction('.tabCInner', 3);
	
	$('.prt-itemList ul').flatHeightsAction_auto();
	
	$('.prt-itemListC').flatHeightsAction('.title', 3);
	
	$('.columnC-B .prt-itemListD').flatHeightsAction('.image', 2);
	$('.columnC-B .prt-itemListD').flatHeightsAction('.title', 2);
	$('.columnC-B .prt-itemListD').flatHeightsAction('.price', 2);
	$('.prt-itemListD ul').flatHeightsAction_auto();
	
	$('.prt-itemListE ul').flatHeightsAction_auto();
	$('.prt-itemListE p.image').flatHeights();
	
	$('.prt-itemListF ul').flatHeightsAction_auto();
	$('.prt-itemListF').flatHeightsAction('.image', 3);
	$('.prt-itemListF').flatHeightsAction('.title', 3);
	$('.prt-itemListF').flatHeightsAction('.price', 3);
	
	$('.prt-rankingListA').flatHeightsAction('.bland', 5);
	$('.prt-rankingListA').flatHeightsAction('.price', 5);
	
	$('.prt-divideCol2A').flatHeightsAction('.unitM-body', 2);
	
	$('.prt-itemListB ul p.item').flatHeights();
	$('.prt-itemListB ul p.brand').flatHeights();
	$('.prt-itemListB ul').flatHeightsAction_auto();
	
	$('.prt-listD ul').flatHeightsAction_auto();
});

$(window).resize(function(){
	$('.prt-itemListB ul').flatHeightsAction_auto();
});


/**
 * iPhone / Android で、overflow:autoのところが表示できないので、
 * のheightをautoにする。
 */

if ((navigator.userAgent.indexOf('iPhone') > 0 || navigator.userAgent.indexOf('iPad') > 0) || navigator.userAgent.indexOf('iPod') > 0 || navigator.userAgent.indexOf('Android') > 0) {
	$(function(){
		$('#main div.prt-regulations .regulationsA .regulations-body .inner,\
			 #main div.prt-regulations .regulationsB .regulations-body .inner')
			.css({
				'height': 'auto'
			});
	});
}

/**
 * 画像の中央揃え
 * @require: jquery.js,
 * @modify : 2011-09-14 - mori@skillpartners.co.jp
 * @modify : 2011-09-30 - mori@skillpartners.co.jp
 */

if(navigator.userAgent.indexOf("MSIE 6") !== -1 || navigator.userAgent.indexOf("MSIE 7") !== -1){
	$(window).load(function(){
		
		var $elms = $('div.prt-itemListB .image');
			
		$elms.each(function(){
			var $img = $(this).find('img');
			var h = $img.height();
			var pt = 0;
		
			if (h < 154) {
				pt = (154 - h) / 2;
			}
		
			$img.css({
				'padding-top': pt
			});
		});
	});
}

$(window).load(function(){
	
	var $elms = $('div.prt-rankingListA .image');
		
	$elms.each(function(){
		var $img = $(this).find('img');
		var h = $img.height();
		var pt = 0;
	
		if (h < 154) {
			pt = (154 - h) / 2;
		}
	
		$img.css({
			'padding-top': pt
		});
	});
});

$(window).load(function(){
	
	var $elms = $('div.prt-itemUnit .image');
		
	$elms.each(function(){
		var $img = $(this).find('img');
		var h = $img.height();
		var pt = 0;
	
		if (h < 154) {
			pt = (154 - h) / 2;
		}
	
		$img.css({
			'padding-top': pt
		});
	});
});



/**
 * ヘッダー：キーワード検索のラジオボタンのclass付け替え
 *
 * @create: 2011-09-20 [oosugi@skillpartners.co.jp]
 * @modify: not yet
 */

$(function(){
	var $elm = $('#headerTools .keywordSearch .scope');
	var $label = $elm.find('label');
	var $radios = $label.find('input:radio');
	
	$label.find('input:checked').parent().addClass('selected');
	
	$label.click(function(e){
		var $this = $(this);
		$label.removeClass('selected');
		$this.addClass('selected');
	});
});



/**
 * スムーススクロール設定
 *
 * @require: jquery.js, jquery.regex.js, jquery.mk_smoothScroll
 * @create: 2011-10-25 [hosono@skillpartners.co.jp]
 * @modify: not yet
 */

//$(function(){
//	// set $.fn.mk_smoothScroll
//	// ページ内アンカーリンクをすべてスムーススクロールにする。
//	$('a:regex(href,.*?#):not(a[href=#]):not(a[target])').mk_smoothScroll();
//});

})(jQuery); //end jquery


/**
 *  UserVoiceの振り出しエリア全体をクリックリンクにする
 */
function createLinkAreaOnUserVoice() {
  //みんなのボイスなう！
  $('.prt-voice .voiceUnit').each(function(){
      var $this = $(this);
      var href = $this.find('a').attr('href');

      //リンク範囲を広げる
      $this
      .click(function(e){
        window.location = href;
        e.preventDefault();
        e.stopPropagation();
        })
      .css({
        'cursor': 'pointer'
        });

      //オーバーでclass付与
      $this
      .mouseenter(function(){
        $(this).closest('li').addClass('js-hover');
        })
      .mouseleave(function(){
        $(this).closest('li').removeClass('js-hover');
        });
  });

}


/**
 * Release Notes:
 *
 * 2011-08-11 - oosugi@skillpartners.co.jp
 *              リンク範囲設定追加（prt-itemSlider, prt-rankingListA, みんなのボイスなう！）
 */

