jQuery(document).ready(function($) {

// focas blur /////////////////////////////////////////////////////////////////
	$('a').focus(function(){this.blur();});

//トップリンクボックス////////////////////////////////////////////////////////////////////
	$('.hoverbox').hover(
		function(){$(this).addClass("readmore_selected");},
		function(){$(this).removeClass("readmore_selected");}
		);
	$('.hoverbox').click(function(){
		var thisURL = window.location;
		var linkURL = $(this).children('h2').children('a').attr('href');
		location.href = linkURL;
	});

//scroll menu ////////////////////////////////////////////////////////////////////
	$('.scroll-menu').scrollFollow({speed:750,offset:10,delay:60});

//PNG fix////////////////////////////////////////////////////////////////////
	$("img[src$='.png']").addClass("png_bg");

//外部リンクのアイコンと_blank追加////////////////////////////////////////////////////////////////////
$('#contents_area a[href^="http"]:not(:has(img))').not('[href*="www.wochikochi.jp"]').append("<img src='http://www.wochikochi.jp/img/linkout.png' width='11' height='11' class='linkout' />")
$('a[href^="http"]').not('[href*="www.wochikochi.jp"]').click(function(){window.open(this.href, '');return false;});

//global navigation over////////////////////////////////////////////////////////////////////
$('#sidemenu li a')
	.css({backgroundPosition:"-242px 0","background-position-x":"-242px"})
	.hover(
		   function(){$(this).stop().animate({"background-position":"0 0","background-position-x":"0"},{duration:600})},
		   function(){$(this).stop().animate({"background-position":"-242px 0","background-position-x":"-242px"},{duration:300})}
		   );
$("#sidemenu li a[target]:not(:has(img)),#sidemenu_network a,#sidemenu_japanese a").hover(
		function(){$(this).append("<img src='http://www.wochikochi.jp/img/linkout.png' width='11' height='11' class='linkout' />");},
		function(){$(".linkout").remove();}
);


//をちこちSearchアコーディオン////////////////////////////////////////////////////////////////////
$('.area h3 a').click(function(){
	var thisClass = $(this).parents('h3').attr('class');
	$(this).parents('.area').find('.inner').slideToggle('fast');
	if (thisClass == 'current'){
		$(this).parents('h3').removeClass();
	} else {
		$(this).parents('h3').addClass('current');
	}
	return false;
});

//global navigation current////////////////////////////////////////////////////////////////////
var thisURL = location.href;
var dirArray = new Array('topstory','special','serialessay','relayessay','foreign','report','recommend');
if (thisURL == 'http://www.wochikochi.jp/' || thisURL == 'http://www.wochikochi.jp/english/'){
	$('#sidemenu_home a').css({background:'#000',color:'#fff'});
} else {
	for(i in dirArray){
		if(thisURL.match(dirArray[i])){
			$('#sidemenu_'+dirArray[i]+' a').css({background:'#000',color:'#fff'});
			break;
		}
	}
}


//関連事業タグリンク生成////////////////////////////////////////////////////////////////////
var tagArray = new Array();
tagArray["日本文化紹介派遣（主催・助成）"] = "http://www.jpf.go.jp/j/culture/human/dispatch/index.html";
tagArray["文化人招へい"] = "http://www.jpf.go.jp/j/culture/human/invitation/index.html";
tagArray["中学高校教員交流"] = "http://www.jpf.go.jp/j/culture/civil/teacher/index.html";
tagArray["文化協力（主催・助成）"] = "http://www.jpf.go.jp/j/culture/human/cooperation/index.html";
tagArray["国際展"] = "http://www.jpf.go.jp/j/culture/exhibit/international/index.html";
tagArray["企画展"] = "http://www.jpf.go.jp/j/culture/exhibit/index.html";
tagArray["国際交流基金巡回展"] = "http://www.jpf.go.jp/j/culture/exhibit/oversea/traveling/index.html";
tagArray["海外展助成"] = "http://www.jpf.go.jp/j/culture/exhibit/oversea/index.html";
tagArray["市民青少年美術交流助成"] = "http://www.jpf.go.jp/j/culture/civil/exchange/support.html";
tagArray["造形美術情報交流"] = "http://www.jpf.go.jp/j/culture/exhibit/exchange/index.html";
tagArray["公演事業（主催・国際共同制作）"] = "http://www.jpf.go.jp/j/culture/perform/index.html";
tagArray["海外公演（助成）"] = "http://www.jpf.go.jp/j/culture/perform/oversea/index.html";
tagArray["パフォーミング・アーツ・ジャパン（助成プログラム）"] = "http://www.jpf.go.jp/j/culture/perform/oversea/index.html";
tagArray["舞台芸術情報交流"] = "http://www.jpf.go.jp/j/culture/perform/exchange/index.html";
tagArray["国際図書展参加"] = "http://www.jpf.go.jp/j/culture/media/publish/index.html";
tagArray["日本理解促進出版・翻訳助成"] = "http://www.jpf.go.jp/j/culture/media/publish/index.html";
tagArray["テレビ番組交流促進"] = "http://www.jpf.go.jp/j/culture/media/media/index.html";
tagArray["海外日本映画上映（主催・助成）"] = "http://www.jpf.go.jp/j/culture/media/oversea/index.html";
tagArray["日本理解促進映像制作（助成）"] = "http://www.jpf.go.jp/j/culture/media/media/index.html";
tagArray["映像出版情報交流"] = "http://www.jpf.go.jp/j/culture/media/exchange/index.html";
tagArray["国際漫画賞"] = "http://www.mofa.go.jp/mofaj/gaiko/culture/koryu/pop/manga/";
tagArray["市民青少年映像・文芸交流助成"] = "http://www.jpf.go.jp/j/culture/civil/exchange/support.html";
tagArray["中国の高校生の招へい事業(長期招へい)"] = "http://www.chinacenter.jp/japanese/kouryu/choki/";
tagArray["心連心"] = "http://www.chinacenter.jp/";
tagArray["日本/中国国内担い手ネットワーク構築"] = "http://www.chinacenter.jp/japanese/about/network/index.html";
tagArray["中国「ふれあいの場」"] = "http://www.chinacenter.jp/japanese/fureai/index.html";
tagArray["中国「ふれあいの場」助成"] = "http://www.chinacenter.jp/japanese/fureai/index.html";
tagArray["日本語専門家派遣"] = "http://www.jpf.go.jp/j/japanese/dispatch/index.html";
tagArray["さくら中核事業"] = "http://www.jpf.go.jp/j/japanese/network/index.html";
tagArray["日本語能力試験"] = "http://www.jlpt.jp/";
tagArray["海外日本語教育機関等調査"] = "http://www.jpf.go.jp/j/japanese/survey/country/index.html";
tagArray["日本語教育指導者養成プログラム（修士課程）"] = "http://www.jpf.go.jp/j/urawa/trnng_t/trnng_t.html";
tagArray["日本言語文化研究プログラム（博士課程）"] = "http://www.jpf.go.jp/j/urawa/trnng_t/trnng_t.html";
tagArray["海外日本語教師上級研修"] = "http://www.jpf.go.jp/j/urawa/trnng_t/trg_09.html";
tagArray["海外日本語教師研修"] = "http://www.jpf.go.jp/j/urawa/trnng_t/trnng_t.html";
tagArray["専門日本語研修"] = "http://www.jpf.go.jp/j/kansai/programs/j_programs.html";
tagArray["日本語学習者訪日研修"] = "http://www.jpf.go.jp/j/kansai/programs/j_programs.html";
tagArray["日本語教材・教授法開発"] = "http://www.jpf.go.jp/j/japanese/resource/index.html";
tagArray["日本研究機関支援"] = "http://www.jpf.go.jp/j/intel/study/support/index.html";
tagArray["日本研究フェローシップ"] = "http://www.jpf.go.jp/j/intel/study/fellowship/index.html";
tagArray["日本研究ネットワーク強化"] = "http://www.jpf.go.jp/j/intel/study/index.html";
tagArray["知的リーダー交流"] = "http://www.jpf.go.jp/j/intel/exchange/organize/index.html";
tagArray["知的交流会議（主催）"] = "http://www.jpf.go.jp/j/intel/exchange/organize/index.html";
tagArray["知的交流会議（助成）"] = "http://www.jpf.go.jp/j/intel/exchange/support/index.html";
tagArray["日米交流支援"] = "http://www.jpf.go.jp/cgp/exchange/index.html";
tagArray["安倍フェローシップ"] = "http://www.jpf.go.jp/cgp/fellow/abe/index.html";
tagArray["日米草の根交流コーディネーター派遣（JOI）プログラム"] = "http://www.jpf.go.jp/cgp/fellow/joi/index.html";
tagArray["国際交流基金賞"] = "http://www.jpf.go.jp/j/about/award/index.html";
tagArray["国際交流基金地球市民賞"] = "http://www.jpf.go.jp/j/about/citizen/index.html";
tagArray["JFIC事業"] = "http://www.jpf.go.jp/j/about/jfic/index.html";
tagArray["国内連携促進"] = "http://www.jpf.go.jp/j/about/jfic/relation/index.html";
tagArray["後援名義の付与"] = "http://www.jpf.go.jp/j/program/others.html#02";
tagArray["国際交流基金への寄附"] = "http://www.jpf.go.jp/j/support/index.html";

tagArray["Introduction of Japanese Culture (Organizer/Support)"] = "http://www.jpf.go.jp/e/culture/human/index.html";
tagArray["Invitations to Distinguished Visitors"] = "http://www.jpf.go.jp/e/culture/human/index.html";
tagArray["Building of Networks Among Leaders"] = "http://www.jpf.go.jp/e/culture/civil/index.html";
tagArray["Cultural Cooperation (Organizer/Support)"] = "http://www.jpf.go.jp/e/culture/human/index.html";
tagArray["International Exhibition"] = "http://www.jpf.go.jp/e/culture/exhibit/international/index.html";
tagArray["Exhibition"] = "http://www.jpf.go.jp/e/culture/exhibit/index.html";
tagArray["Exhibition Abroad Program"] = "http://www.jpf.go.jp/e/culture/exhibit/oversea/traveling/index.html";
tagArray["Exhibition Abroad Support Program"] = "http://www.jpf.go.jp/e/culture/exhibit/oversea/index.html";
tagArray["Support Program for Visual Arts Events Abroad at the Grass-roots Level"] = "http://www.jpf.go.jp/e/culture/civil/index.html";
tagArray["Visual Arts Sharing Information"] = "http://www.jpf.go.jp/e/culture/perform/exchange/index.html";
tagArray["Performance Programs (Organizer/International Collaboration)"] = "http://www.jpf.go.jp/e/culture/perform/index.html";
tagArray["Overseas Performance (Support)"] = "http://www.jpf.go.jp/e/culture/perform/oversea/index.html";
tagArray["Performing Arts Japan (Support)"] = "http://www.jpf.go.jp/e/culture/perform/oversea/index.html";
tagArray["Performing Arts Sharing Information"] = "http://www.jpf.go.jp/e/culture/perform/exchange/index.html";
tagArray["International Book Fair"] = "http://www.jpf.go.jp/e/culture/media/publish/index.html";
tagArray["Support Program for Translation and Publication on Japan"] = "http://www.jpf.go.jp/e/culture/media/publish/index.html";
tagArray["Support Program for TV Program Production on Japan"] = "http://www.jpf.go.jp/e/culture/media/media/index.html";
tagArray["Japanese Film Screenings Overseas (Organize/Support)"] = "http://www.jpf.go.jp/e/culture/media/oversea/index.html";
tagArray["Support Program for Film Production on Japan (Support)"] = "http://www.jpf.go.jp/e/culture/media/media/index.html";
tagArray["Audio-Visual and Publication Sharing Information"] = "http://www.jpf.go.jp/e/culture/media/exchange/index.html";
tagArray["International Manga Award"] = "http://www.mofa.go.jp/policy/culture/exchange/pop/manga/";
tagArray["Support Program for Overseas Activities for Youth and Citizens in the Area of Film TV and Publication"] = "http://www.jpf.go.jp/e/culture/civil/index.html";
tagArray["Long-term Invitation of Chinese High School Students"] = "#";
tagArray["Heart to Heart"] = "#";
tagArray["The Centers for Face-to-Face Exchanges"] = "#";
tagArray["The Centers for Face-to-Face Exchanges(Support)"] = "#";
tagArray["Japanese-Language Specialists Dispatch Program"] = "http://www.jpf.go.jp/e/japanese/dispatch/index.html";
tagArray["Sakura Network"] = "http://www.jpf.go.jp/e/japanese/network/index.html";
tagArray["Japanese Language Proficiency Test"] = "http://www.jlpt.jp/e/index.html";
tagArray["Survey on Japanese-Language Education Abroad"] = "http://www.jpf.go.jp/e/japanese/survey/area.html";
tagArray["Graduate Program on Japanese Language and Culture (Master\'s Course)"] = "http://www.jpf.go.jp/j/urawa/trnng_t/trnng_t.html";
tagArray["Graduate Program on Japanese Language and Culture (Doctor\'s Course)"] = "http://www.jpf.go.jp/j/urawa/trnng_t/trnng_t.html";
tagArray["Advanced Training Program for Teachers of the Japanese-Language"] = "http://www.jpf.go.jp/j/urawa/trnng_t/trg_09.html";
tagArray["Training Programs for Teachers of the Japanese-Language"] = "http://www.jpf.go.jp/j/urawa/trnng_t/trnng_t.html";
tagArray["Japanese-Language Program for Specialists"] = "http://www.jpf.go.jp/j/kansai/programs/j_programs.html	http://www.jfkc.jp/en/training/business-table-H22.html";
tagArray["Training Programs for Japanese-Language Learners in Japan"] = "http://www.jfkc.jp/en/training/business-table-H22.html";
tagArray["Japanese-Language Teaching Materials and Methods"] = "http://www.jpf.go.jp/e/japanese/resource/index.html";
tagArray["Support for Japanese Studies Organizations"] = "http://www.jpf.go.jp/e/intel/study/support/index.html";
tagArray["Japanese Studies Fellowship"] = "http://www.jpf.go.jp/e/intel/study/fellowship/index.html";
tagArray["Building of Japanese Studies Network"] = "http://www.jpf.go.jp/e/intel/study/index.html";
tagArray["Intellectual Leaders\' Exchange"] = "http://www.jpf.go.jp/e/intel/exchange/organize/index.html";
tagArray["Intellectual Exchange Conferences (Organizer)"] = "http://www.jpf.go.jp/e/intel/exchange/organize/index.html";
tagArray["Intellectual Exchange Conferences (Support)"] = "http://www.jpf.go.jp/e/intel/exchange/support/index.html";
tagArray["CGP Grant Program"] = "http://www.jpf.go.jp/cgp/e/";
tagArray["Abe Fellowship Program"] = "http://www.jpf.go.jp/cgp/e/fellow/abe/index.html";
tagArray["Japan Outreach Initiative (JOI) Program"] = "http://www.jpf.go.jp/cgp/e/fellow/joi/index.html";
tagArray["The Japan Foundation Awards"] = "http://www.jpf.go.jp/e/about/award/index.html";
tagArray["The Japan Foundation Prizes for Global Citizenship"] = "http://www.jpf.go.jp/e/about/citizen/index.html";
tagArray["JFIC Activity"] = "http://www.jpf.go.jp/e/about/jfic/index.html";
tagArray["JF Supporters Club"] = "http://www.jpf.go.jp/j/about/jfic/relation/index.html";
tagArray["Granting the Use of the Name of the Japan Foundation as a Supporter"] = "http://www.jpf.go.jp/e/program/others.html#02";
tagArray["Designated Donations Program"] = "http://www.jpf.go.jp/e/support/index.html";

$('#relatedTags li a').each(function(){
	var tagLabel = $(this).text();
	$(this).attr('href',tagArray[tagLabel]);
});

//scroll-pan////////////////////////////////////////////////////////////////////
$('.scroll-pane').jScrollPane({scrollbarWidth:4});
$('#sidesearchGenre .jScrollPaneTrack').css( 'background','#aaa');
$('#sidesearchGenre .jScrollPaneDrag').css( 'background','#666');

//PDFバックナンバーカルーセル////////////////////////////////////////////////////////////////////
var i = 1;
$('#PDFbackNumberH .next').click(function(){
	if(i < 8){
		carY = (i*664);
		$('#carCont').animate({ left: '-'+carY+"px" },500);
		i++;
		$('#PDFbackNumberH .prev').show();
	}
	if(i == 8){ $(this).hide(); }
});
$('#PDFbackNumberH .prev').click(function(){
	if(i > 1){
		i--;
		carY = carY-664
		$('#carCont').animate({ left: '-'+carY+"px" },500);
		$('#PDFbackNumberH .next').show();
	}
	if(i == 1){ $(this).hide(); }
});

var randnum = 1 + Math.floor( Math.random() * 32 );
$('#sidePDF'+randnum).show();


//ページスライダー////////////////////////////////////////////////////////////////////
var j = 0;
var k = $('#contents_right .separator').length;
var thisURL = String(window.location);
var plFlag = thisURL.lastIndexOf('#');
var lW = thisURL.charAt(thisURL.length - 1);

if (k >= 1){//.separatorがあるとき
	//separatorにIDをつける
	$('#contents_right .separator').each(function(){
		j++;
		$(this).attr('id','separator'+j);
	});

	//sliderボタンをappend
	j = 0;
	if( plFlag != -1 && lW != 'p'){ //URLにページ内リンク#hogeがあってかつ#pagetopでないとき
		j = parseInt(lW);
		if (j==1){
			$('#contents_right').append('<ul id="sepSlider"><li class="up"><a href="#pagetop"><img src="/img/slider_up.gif" width="28" height="64" /></a></li><li class="down"><a href="#separator'+(j+1)+'"><img src="/img/slider_down.gif" width="28" height="64" /></a></li></ul>');
		} else {
			$('#contents_right').append('<ul id="sepSlider"><li class="up"><a href="#separator'+(j-1)+'"><img src="/img/slider_up.gif" width="28" height="64" /></a></li><li class="down"><a href="#separator'+(j+1)+'"><img src="/img/slider_down.gif" width="28" height="64" /></a></li></ul>');
		}
		$('#sepSlider .up a').show();
	} else {//通常
		$('#contents_right').append('<ul id="sepSlider"><li class="up"><a href="#pagetop"><img src="/img/slider_up.gif" width="28" height="64" /></a></li><li class="down"><a href="#separator'+(j+1)+'"><img src="/img/slider_down.gif" width="28" height="64" /></a></li></ul>');
	}

	//downをクリックしたとき
	$('#sepSlider .down').click(function(){
		j++;
		if(j>1&&j<k){
			$('#sepSlider .up').find('a').attr('href','#separator'+(j-1));
			$(this).find('a').attr('href','#separator'+(j+1));
			$('#sepSlider .up a').show();
		} else if (j==1) {
			$('#sepSlider .up').find('a').attr('href','#pagetop');
			$(this).find('a').attr('href','#separator'+(j+1));
			$('#sepSlider .up a').show();
		} else {
			$('#sepSlider .down a').hide();
		}
		
	});

	//upをクリックしたとき
	$('#sepSlider .up').click(function(){
		j--;
		if(j>1){
			$(this).find('a').attr('href','#separator'+(j-1));
			$('#sepSlider .down').find('a').attr('href','#separator'+(j+1));
			$('#sepSlider .down a').show();
		} else if (j==1) {
			$(this).find('a').attr('href','#pagetop');
			$('#sepSlider .down').find('a').attr('href','#separator'+(j+1));
		} else if (j==0) {
			$(this).find('a').hide();
			$('#sepSlider .down').find('a').attr('href','#separator'+(j+1));
		} 
	});

	//Sliderマウスオーバー
	$('#sepSlider img').hover(function(){
		$(this).css('opacity','0.5');
	},function(){
		$(this).css('opacity','1');
	});

	//Sliderスクロールフォロー
	$('#sepSlider').scrollFollow({speed:250,offset:10,delay:0});
}

// をちこちサーチPDFの日付からDayを削除
$('.date .iconPDF').each(function(){
var xDate = $(this).parent('dt').find('span').text();
var newDate = xDate.substr(0,7);
$(this).parent('dt').find('span').text(newDate);
});
$('.date span').show();

});//ready function End;


//PDFバックナンバージャンプメニュー//////////////////////////////////////////////////////////////////
function MM_jumpMenu(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

