$(function(){
//ページのスムーズスクロール
	if(navigator.userAgent.indexOf("Opera") != -1){
		if(document.compatMode == 'BackCompat'){
			var scrollTarget = 'body';
		} else {
			var scrollTarget = 'html';
		}
	} else {
		var scrollTarget = 'html,body';
	}
	$(function(){
		$("li.backTop").click(function(){
			$((navigator.userAgent.indexOf("Opera") != -1) ? document.compatMode == 'BackCompat' ? 'body' : 'html' :'html,body').animate({scrollTop:0}, 'normal');
		})
	})


// 画像のロールオーバー（srcに _ov を自動で追加する）
	var postfix = '_ov';
	$('a img.hover, #subNav li a img, #globalNav li a img, #footerNav li a img, #localNav a img, #topNav li a img').not('[src*="'+ postfix +'."]').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);
			}
		);
	});

// 文字サイズの変更
	//文字サイズのボタン画像のsrcを保存する
	btn_src = new Array(2);
	$("#fontScaler a img").each(function (i) {
		btn_src[i] = $(this).attr('src');
	});

	//Cookieを読み込んで、以前の文字サイズに設定する
	if($.cookie('kyodo_fontscale')) {
		var fontscale_value = $.cookie('kyodo_fontscale');
		$('body').addClass(fontscale_value);
		fontScaleButton(fontscale_value);
	} else {
		var fontscale_value = 'scaleM';
		fontScaleButton(fontscale_value);
	}
	$('#fontScaler a').click(function() {
		var textSize = $(this).attr('class');
		//ボタン画像を初期化
		$('#fontScaler a.scaleS img').attr('src', btn_src[0]);
		$('#fontScaler a.scaleM img').attr('src', btn_src[1]);
		$('#fontScaler a.scaleL img').attr('src', btn_src[2]);
		//クリックした画像を _on に変える
		fontScaleButton(textSize);
		$('body').removeClass('scaleS scaleM scaleL').addClass(textSize);
		$.cookie('kyodo_fontscale', textSize, { expires: 365, path: '/'});
		var text_size = $.cookie('kyodo_fontscale');
		return false;
	})
});


//現在の文字サイズのボタン画像を _on に変える
function fontScaleButton (className) {
	var loaded_img = '_on';
	var scale_img = $('#fontScaler a.' + className +' img').attr('src');
	var scale_img_on = scale_img.substr(0, scale_img.lastIndexOf('.'))
						+ loaded_img
						+ scale_img.substring(scale_img.lastIndexOf('.'));
	$('#fontScaler a.' + className +' img').attr('src', scale_img_on);
	return false;
}


// 別ウィンドウを開くスクリプト
// 記述：onclick="javascript:WindowCtrlOpen(this.href,'',600,580);return false" onkeypress="onclickと同じ内容"
//-----------------------------------
function WindowCtrlOpen(url,windowname,width,height) {

	var features="location=no, menubar=no, status=no, scrollbars=yes, resizable=yes, toolbar=no, directories=no";

	if (width) {

		if (window.screen.width > width)

		features+=", left="+(window.screen.width-width)/2;

		else width=window.screen.width;

		features+=", width="+(width+0);

	}

	if (height) {

		if (window.screen.height > height)

		features+=", top="+(window.screen.height-height)/2;

		else height=window.screen.height;

		features+=", height="+(height+10);

	}

	window.open(url,windowname,features);

}
