$(function(){

    //gnav hover
    var postfix = '_on';
    $('#gNav a img').not('[src*="'+ postfix +'."], #textsize').each(function() {
        var img = $(this);
        var src = img.attr('src');
        var src_on = src.substr(0, src.lastIndexOf('.'))
                   + postfix
                   + src.substring(src.lastIndexOf('.'));
				   
        $('<img>').attr('src', src_on);
        img.hover(
            function() {
                img.attr('src', src_on);
            },
            function() {
                img.attr('src', src);
            });
    });
	
	//sideNav
	$('#subNav ul:first').addClass('sideNav');
	

    //検索窓 focus
	$('#searchArea input[type="text"]').focus(function(){
		$(this).addClass('focus');
	})
	.blur(function(){
		if($(this).val()==''){
			$(this).removeClass('focus');
		}
		else{
			$(this).addClass('focus');
		};
	}).blur();

    //listLine
    $('#footer ul.listLine li:last-child, #header ul.listLine li:last-child').addClass('listLast');
	
	//home banner
	$('#topPage #recruitBanner a img:not(:last)').addClass("imgSpace");

	//sitemap
	$("#grp09sitemap #main #sitemapWrap .sitemapCate:first").addClass("sitemapLeft");

	//外部リンクアイコン
	$('#main a[href^="http"]:not(:has(img))').not('#topPage #main h2 a, #searchResultsPage #main a').attr('target','_blank').after('&nbsp;<img src="/common/images/icon_window.gif" alt="外部リンク" width="12" height="10" class="exlinkicon" />');
	$('#main a[href$=".pdf"], #main a[href$=".PDF"], #main a[href$=".doc"], #main a[href$=".docx"], #main a[href$=".xls"], #main a[href$="txt"]').attr('target','_blank');
	
	//ページ内リンク #pageLink
	var prefix = 'pageh2';
	var pagelinkli = '';
	var count = 0; //textPageTopにて使用
	$('#main h2').not('#topPage #main h2, #searchResultsPage #main h2').each(function(i,j){
		aname = prefix + i;
		$(this).attr('id', aname);
		pagelinkli += '<li><a href="#' + aname + '">' + $(this).text() + '</a></li>';
		count = count + 1;
	});
	$('#main #pageLink ul').prepend(pagelinkli);
	//ページの先頭へ戻るリンク .textPageTop
	var textpagetop = '<p class="textPageTop"><a href="#header">ページの先頭に戻る</a></p>';
	if(count > 1){
		$('#main h2').not('#topPage #main h2, #searchResultsPage #main h2, #main .layout h2, #main h2:first, #sitemapWrap h2').before(textpagetop);
	};

	//pickup top
	$('#pickupContents .pickupIn:odd').addClass('f-right');
	$('#pickupContents .pickupIn:even').addClass('f-left');
	$('#pickupContents .pickupIn:not(:has("img"))').find('dl').addClass('dlNoPhoto');
	var wrappick = '<div class="pickup clearfix"></div>';
	$('#pickupContents .pickupIn').slice(0,2).wrapAll(wrappick);
	$('#pickupContents .pickupIn:gt(1)').slice(0,2).wrapAll(wrappick);
	$('#pickupContents .pickupIn:gt(3)').slice(0,2).wrapAll(wrappick);
	$('#pickupContents .pickupIn:gt(5)').slice(0,2).wrapAll(wrappick);
	$('#pickupContents .pickupIn:gt(7)').slice(0,2).wrapAll(wrappick);

	//informationContents categorytop
	$('#infoContents .informationIn:odd').addClass('f-right');
	$('#infoContents .informationIn:even').addClass('f-left');
	//$('#infoContents .informationIn:not(:has("img"))').find('div').addClass('infoNoPhoto');
	var wrapinfo = '<div class="information clearfix"></div>';
	$('#infoContents .informationIn').slice(0,2).wrapAll(wrapinfo);
	$('#infoContents .informationIn:gt(1)').slice(0,2).wrapAll(wrapinfo);
	$('#infoContents .informationIn:gt(3)').slice(0,2).wrapAll(wrapinfo);
	$('#infoContents .informationIn:gt(5)').slice(0,2).wrapAll(wrapinfo);
	$('#infoContents .informationIn:gt(7)').slice(0,2).wrapAll(wrapinfo);
	$('#infoContents .informationIn:gt(9)').slice(0,2).wrapAll(wrapinfo);

	//pager
	var countPagerCurrent = $('#pageChange li.numberSelect').text();
	var countPagerTotal = $('#pageChange li:last').text();
	var countPagerRight = Number(countPagerCurrent) + 2;
	var countPagerLeft = Number(countPagerCurrent) - 2;
	if(countPagerTotal >= 11){
		if(countPagerCurrent >= 6){
			if((countPagerLeft > 3)&&((countPagerTotal - countPagerRight) > 2)){
				countPagerLeft = countPagerLeft - 1;
				$('#pageChange li:lt(' + countPagerLeft + ')').hide();
			    $('#pageChange li:eq(' + countPagerLeft + ')').before("<li>...</li>");
				$('#pageChange li:first, #pageChange li:eq(1)').show();
			}else{
				countPagerLeft = countPagerLeft + (countPagerTotal - countPagerRight) - 4;
				$('#pageChange li:lt(' + countPagerLeft + ')').hide();
			    $('#pageChange li:eq(' + countPagerLeft + ')').before("<li>...</li>");
				$('#pageChange li:first, #pageChange li:eq(1)').show();
			};
		}
		if((countPagerTotal-countPagerRight > 3)&&(countPagerTotal > countPagerRight)&&(countPagerCurrent > 5)){
				$('#pageChange li:gt(' + countPagerRight + ')').hide();
			    $('#pageChange li:eq(' + countPagerRight + ')').after("<li>...</li>");
				$('#pageChange li:last').show();
				$('#pageChange li:last').prev().show();
		}else if((countPagerTotal-countPagerRight > 3)&&(countPagerTotal > countPagerRight)&&(countPagerCurrent < 6)){
				$('#pageChange li:gt(7)').hide();
			    $('#pageChange li:eq(7)').after("<li>...</li>");
				$('#pageChange li:last').show();
				$('#pageChange li:last').prev().show();
		};
	};

	//ulLink
	$('#main ul').not('#topPage #main ul').each(function(i){
		var linkcount = 0;
		var licount = 0;
		if($(this).hasClass("list") || $(this).hasClass("listLink") || $(this)[id="hierarchyLink"] || $(this).parent().parent().hasClass("relatedLink") || $(this).hasClass("numberArea")){
		}
		else {
			$(this).children('li').each(function(){
				licount += 1;
			});
			$(this).find('a').each(function(){
				linkcount += 1;
			});

			if(licount == linkcount){
				$(this).addClass('ulLink');
			};
		};
	});
	
	//easing scroll
	$("a[href*='#']").easingScroll({
		easing: "easeOutQuad",
		duration: 700
	});

	//form input width
	$('#FormArea table :text, #FormArea table textarea').addClass('inputTxt');
	//form required
	var required = '<span class="note">(必須)</span>';
	$('#FormArea table th:contains("必須")').each(function(){
		$(this).html($(this).html().replace(/(\(必須\))/g, required));
		$(this).html($(this).html().replace(/(（必須）)/g, required));
	});
	
	//layout
	$('.layout .layout1_1:first-child').addClass('layoutSpaceR');
		
});

    //fontsize
(function($){

	$(function(){
		fontsizeChange();
	});

	function fontsizeChange(){

		var changeArea = $("#wrap");			//フォントサイズ変更エリア
		var btnArea = $("#textsize");				//フォントサイズ変更ボタンエリア
		var changeBtn = btnArea.find(".changeBtn");	//フォントサイズ変更ボタン
		var fontSize = [75,88,100];				//フォントサイズ（HTMLと同じ並び順、幾つでもOK、単位は％）
		var ovStr = "_on";		//ロールオーバー画像ファイル末尾追加文字列（ロールオーバー画像を使用しない場合は値を空にする）
		var activeClass = "active";					//フォントサイズ変更ボタンのアクティブ時のクラス名
		var defaultSize = 0;						//初期フォントサイズ設定（HTMLと同じ並び順で0から数値を設定）
		var cookieExpires = 7;					//クッキー保存期間
		var sizeLen = fontSize.length;
		var useImg = ovStr!="" && changeBtn.is("[src]");

		//現在クッキー確認関数
		function nowCookie(){
			return $.cookie("fontsize");
		}

		//画像切替関数
		function imgChange(elm1,elm2,str1,str2){
			elm1.attr("src",elm2.attr("src").replace(new RegExp("^(\.+)"+str1+"(\\.[a-z]+)$"),"$1"+str2+"$2"));
		}

		//マウスアウト関数
		function mouseOut(){
			for(var i=0; i<sizeLen; i++){
				if(nowCookie()!=fontSize[i]){
					imgChange(changeBtn.eq(i),changeBtn.eq(i),ovStr,"");
				}
			}
		}

		//フォントサイズ設定関数
		function sizeChange(){
			changeArea.css({fontSize:nowCookie()+"%"});
		}

		//クッキー設定関数
		var cookieSet = function(index){
			$.cookie("fontsize",fontSize[index],{path:'/',expires:cookieExpires});
		}

		//初期表示
		if(nowCookie()){
			for(var i=0; i<sizeLen; i++){
				if(nowCookie()==fontSize[i]){
					sizeChange();
					var elm = changeBtn.eq(i);
					if(useImg){
						imgChange(elm,elm,"",ovStr);
						imgChange($("<img>"),elm,"",ovStr);
					}
					elm.addClass(activeClass);
					break;
				}
			}
		}
		else {
			cookieSet(defaultSize);
			sizeChange();
			var elm = changeBtn.eq(defaultSize);
			if(useImg){
				imgChange(elm,elm,"",ovStr);
			}
			else {
				elm.addClass(activeClass);
			}
		}

		//ホバーイベント（画像タイプ）
		if(useImg){
			changeBtn.each(function(i){

				var self = $(this);

				self.hover( //ホバーイベント
				function(){
					if(nowCookie()!=fontSize[i]){
					imgChange(self,self,"",ovStr);
					}
				},
				function(){
					mouseOut();
				})

			});

		}

		//クリックイベント
		changeBtn.click(function(){

			var index = changeBtn.index(this);
			var self = $(this);

			cookieSet(index);
			sizeChange();

			if(useImg){
				mouseOut();
			}
			if(!self.hasClass(activeClass)){
				changeBtn.not(this).removeClass(activeClass);
				self.addClass(activeClass);
			}

		});

	}

})(jQuery);


