/*====================================================================================================
//////////////////////////////////////////////////////////////////////////////////////////////////////

	common.js サイト内共用JS

//////////////////////////////////////////////////////////////////////////////////////////////////////
====================================================================================================*/
(function($){
	$.ajaxSetup({async: false});
	$.getScript('/common/js/jquery.shadow.js');
	$.getScript('/common/js/jquery.pngFix.js');
	$.getScript('/common/js/jquery.lightpop-0.8.5.1.js');
	$.getScript('/common/js/modalwindow.js');
	$.getScript('/common/js/jquery-opacity-rollover.js');
	$.ajaxSetup({async: true});

	$(function(){
		// pngfix
		// ---------------------------------------------------------------------
		$('img[src$=.png], .pngfix').pngFix({ blankgif: '/common/images/blank.gif' });

		// 「戻る」ボタンの位置制御（2カラムか3カラムで変わる）
		// ---------------------------------------------------------------------
		if ($('#container03').length) {
			$('#titleArea #historyBack').addClass('col3');
		}

		// ロールオーバー処理
		// ---------------------------------------------------------------------
		$('img.ov').each(function(){
		      //srcセット
		      rolloverSrc = $(this).attr('src').replace(/(\.gif|\.jpg|\.png)$/, "_r"+"$1");

		      //イメージセット
		      $(this).clone().insertAfter(this)
		        .attr('src',rolloverSrc)
		        .css('display','none');

		      //ロールオーバー(マウスオン時)
		      $(this).mouseover(function(){
		        $(this).hide();
		        $(this).next().show();
		      });
		      //ロールオーバー(マウスアウト時)
		      $(this).next().mouseout(function(){
		        $(this).hide();
		        $(this).prev().show();
		      });
		  });

		// ナビメニューの検索フォーム
		// ---------------------------------------------------------------------
		$('#word_search .searchWord')
			.focus(function() {
				$(this).css('backgroundColor', '#FFFFFF');
			})
			.blur(function() {
				var bgColor = ($(this).val().length < 1) ? 'transparent' : '#FFFFFF';
				$(this).css('backgroundColor', bgColor);
			})
			.blur();

		// ライトボックス
		// ---------------------------------------------------------------------
		var imgSelector = '[href$=.jpg], [href$=.gif], [href$=.png]';
		var popupModalWindow = function(){
			yomotsuModalWindow.set(this.href);
			return false;
		};
		//$.fn.fancyzoom.defaultsOptions.imgDir = '/common/images/fancyzoom/';
		$('a.popup, area.popup, a[href$="?popup"]')
			//.filter(imgSelector).fancyzoom().end()
			//.not(imgSelector)
			.live('click', popupModalWindow);
		$('a.lightpop').lightpop({
			grouping: false,
			containerBorderSize: 0,
			boxBorderSize: 0,
			imageBtnCloseWidth: 134,
			grouping: false,
			Contents: {
				iframeEnabled:true,
				scrolling: 'no',
				style: ''
			}
		}, null, null , '/common/images/lightpop/');

		// アルファによるアテンション
		// ---------------------------------------------------------------------
		$('.attention, .subImg a, .productList a img, #catRelatedItem a img, #sideNewItem a').opOver();
		$('#products_list_left a img, #products_list_right a img').opOver();
		$('.lines > dt').opOver(1.0, 0.85);
		$('#gnav a img, #hSiteinfo a img').opOver(1.0, 0.5);
		$('.relativeLinks a img').opOver();
		$('a.opOver img, .opOver a img').opOver();

		// カタログナビ
		// ---------------------------------------------------------------------
		var switchCategoryToggle = function() {
			var button = $('.toggleBtn', this);
			if ($(this).is('.current')) {
				button.attr('src', button.attr('src').replace(/^(.*)?\.(.+)$/, '$1_open.$2'))
				$(this).next('dd').slideDown();
			} else {
				button.attr('src', button.attr('src').replace(/^(.*)?_open\.(.+)$/, '$1.$2'))
				$(this).next('dd').slideUp();
			}
		};

		$('#catalogNavi ul.productNames')
			.find('li.current')
				.closest('ul.productNames').show()
				.closest('dd').prev('dt')
					.addClass('current');

		$('#catalogNavi dl.categories > dt')
			.each(function() {
				if ($(this).next('dd').find('.current').length) {
					$(this).addClass('current');
				}
				if (!$(this).hasClass('current')) {
					$(this).next('dd').hide();
				}
				$.proxy(switchCategoryToggle, this)();
			})
			.find('.toggleBtn')
				.click(function(){
					$(this).closest('dt').toggleClass('current');
					$.proxy(switchCategoryToggle, $(this).closest('dt'))();
				});

		$('#catalogNavi dl.lines > dt')
			.each(function() {
				if ($(this).next('dd').find('.current').length) {
					$(this).addClass('current');
				}
				if (!$(this).hasClass('current')) {
					$(this).next('dd').hide();
				}
			})
			.click(function() {
				if ($(this).next('dd').is(':hidden')) {
					$(this).siblings('dd:visible').slideUp();
					$(this).next('dd').slideToggle();
				}
			});

		// 商品カタログの商品リストの高さ調整
		//$('.productsRow').each(function(){
		//	$('.productBox p', this).autoHeight();
		//	$('.productBox p img', this).css('position', 'absolute');
		//});

		// 商品詳細の説明置換処理
		// ---------------------------------------------------------------------
		$('#catDetail .specification p').each(function(){
			$(this).html($(this).html().replace(
				/^(◎|◇|・|●)(.+)$/,
				'<span class="mark">$1</span><span class="body">$2</span>'
			));
		});

		// 商品画像と商品名のリンクの同期
		// ---------------------------------------------------------------------
		$('.productList .productBox p img').hover(
			function(){	$(this).closest('.productBox').find('dl a').toggleClass('ul'); },
			function(){	$(this).closest('.productBox').find('dl a').toggleClass('ul'); }
		);
		$('#catRelatedItem a.picture').hover(
			function(){ $(this).closest('dd').find('a.name').toggleClass('ul'); },
			function(){ $(this).closest('dd').find('a.name').toggleClass('ul'); }
		);

		// 関連リンクの画像とテキストの下線処理
		// ---------------------------------------------------------------------
		$('ul.relativeLinks li a').hover(
			function(){ $('span.linkA01', this).toggleClass('ul'); },
			function(){ $('span.linkA01', this).toggleClass('ul'); }
		);
	});
})(jQuery);
