/*
 * 設定
 */
var searchString = '検索する文字列を入力';


$(function() {
	
	//ヘッダー検索部
	$('#hnaviSearchWord').css('color','#CCCCCC');
	$('#hnaviSearchWord').attr('value', searchString);
	$('#hnaviSearchWord').focus(function() {
		if($(this).attr('value') == searchString) {
			$(this).attr('value', '');
			$(this).css('color','#333333');
		}
	});
	$('#hnaviSearchWord').blur(function() {
		if(!$(this).attr('value')) {
			$(this).attr('value', searchString);
			$(this).css('color','#CCCCCC');
		}
	});
	
	
	//lnaviジャンル、シリーズ開閉
	$('.lnavi .section .switch').each(function() {
		if($(this).nextAll('ul').html() != null) {
			$(this).click(clickNormal);
		}
		else{
			$(this).addClass('all');
		}
		if($(this).nextAll('ul').children('li').children('a.switch').nextAll('ul').html() != null) {
			$(this).nextAll('ul').children('li').children('a.switch').addClass('lower');
			$(this).nextAll('ul').children('li').children('a.switch').click(function() {
				$(this).unbind('click', clickNormal);
				if($(this).nextAll('ul').css('display') == 'block') {
					$(this).toggleClass('openLower');
					$(this).nextAll('ul').css('display', 'none');
				} else {
					$(this).toggleClass('openLower');
					$(this).nextAll('ul').css('display', 'block');
				}
			});
		}
	});

	function clickNormal() {
		if($(this).nextAll('ul').css('display') == 'block') {
			$(this).toggleClass('open');
			$(this).nextAll('ul').css('display', 'none');
		} else {
			$(this).toggleClass('open');
			$(this).nextAll('ul').css('display', 'block');
		}
	}

	$('.lnavi .section .defaultOpen .switch').each(function() {
		if($(this).nextAll('ul').html() != null) {
			$(this).toggleClass('open');
		}
		if($(this).parents('li.categoryName').get() != null) {
			$(this).parents('li.categoryName').addClass('defaultOpen');
			$(this).parents('li.categoryName').children('a.switch.lower').addClass('openLower');
			$(this).parents('li.categoryName').children('a.switch').addClass('open');
		}
	});
	$('.lnavi .section .categoryName').each(function() {
		var aryCount = 0;
		var noDispCount = 0;
		$('.categoryName',$(this)).each(function() {
			if($(this).css('display') == 'none'){
				noDispCount++;
			}
			aryCount++;
		});
		
		if(aryCount == noDispCount){
			$('.switch',$(this)).css('visibility','hidden');
		}
	});
	$('.lnavi .section#lnaviSeries .switch').each(function() {
		if($(this).parents('li').get() != null) {
			if($(this).nextAll('ul').html() != null) {
				$(this).toggleClass('open');
			}
			$(this).parents('li').addClass('defaultOpen');
			$(this).parents('li').children('a.switch.lower').addClass('openLower');
		}
	});
	$('.lnavi #lnaviSeries.section .entry ul ul a').removeClass('open');
	
	$('#lnaviSeries h2').click(function() {
		$('.lnavi #lnaviSeries.section .title h2').toggleClass('close');
		if($(this).hasClass('close')) {
			$('.lnavi #lnaviSeries.section .contents').css('display','none');
		} else {
			$('.lnavi #lnaviSeries.section .contents').css('display','block');
		}
	});
});

function swap(obj) {
	if (obj.src.match(/.+_on\.[gif|jpg|jpe|jpeg|png]/)) {
		obj.src = obj.src.replace(/(.+)_on(\.[gif|jpg|jpe|jpeg|png])/, '$1$2');
	} else {
		obj.src = obj.src.replace(/(.+)(\.[gif|jpg|jpe|jpeg|png])/, '$1_on$2');
	}
}

