// jQuery Document

$(function() {
	
	// 慣例的な first-child クラス指定
	$("h2:first").addClass("first-child");
	$("h3:first").addClass("first-child");
	$("h4:first").addClass("first-child");
	$("h5:first").addClass("first-child");
	
	$("dl dt:first-child").addClass("first-child");
	
	// 偶数のテーブル行に even クラスをつける（色付用）
	$("table tr:even").addClass("even");
	
	// afterclear
	$(".afterclear").append("<span class='afterclearElem'></span>");
	
	// パンくずリストのスタイルを生成
	$("#pathlist li:last-child").addClass("last-child").wrapInner("<span></span>");
	
	// 外部リンクに target="_blank" をつける
	$("a[href^='http://']").attr("target","_blank");
	$("a[href^='https://']").attr("target","_blank");
	
	// img要素を内包しない外部リンクに.externalLinkクラスをつける
	$("a[href^='http://']:not(:has(img))").addClass("externalLink");
	$("a[href^='https://']:not(:has(img))").addClass("externalLink");
	
	// img要素を内包しないPDFへのリンクに.pdfクラスをつける
	// 外部pdfへの直リンクの場合は.externalLinkクラスを外す など
	$("a[href$='.pdf']:not(:has(img))").addClass("pdf").attr("target","_blank").removeClass("externalLink"); 
	$("a[href$='.txt']:not(:has(img))").addClass("txt").attr("target","_blank").removeClass("externalLink");
	$("a[href$='.doc']:not(:has(img))").addClass("word").removeClass("externalLink");
	$("a[href$='.xls']:not(:has(img))").addClass("xls").removeClass("externalLink");
	$("a[href$='.ppt']:not(:has(img))").addClass("ppt").removeClass("externalLink");
	
	// サムネイルイメージにズームアイコンを重ねる
	$("a:has(img[src$='_s.jpg'])").css("position", "relative")
	.append('<img src="/img/share/ico_zoom.png" alt="クリックすると拡大します" height="20" width="20" class="zoom" />');
	$("a:has(img[src$='_s.png'])").css("position", "relative")
	.append('<img src="/img/share/ico_zoom.png" alt="クリックすると拡大します" height="20" width="20" class="zoom" />');
	$("a:has(img[src$='_s.gif'])").css("position", "relative")
	.append('<img src="/img/share/ico_zoom.png" alt="クリックすると拡大します" height="20" width="20" class="zoom" />');
	$("img[src$='_s.jpg']").addClass("border");
	$("img[src$='_s.png']").addClass("border");
	$("img[src$='_s.gif']").addClass("border");
	
	// .highlight をクリックすると、relを取得し該当idをハイライト
	$(".highlight").toggle(function(){
		var hl = $(this).attr("rel");
		$("#"+hl.toString()).addClass("marker-yellow");
	}, function(){
		var hl = $(this).attr("rel");
		$("#"+hl.toString()).removeClass("marker-yellow");
	});
	
	// 背景を交互に変える
	$(".bg_decoset:even").addClass("even");
	
   	// スムーススクロール
	$('a[href^=#]').click(function(){
    	var speed = 200; // ミリ秒
    	var href= $(this).attr("href");
    	var target = $(href == "#" || href == "" ? 'html' : href);
    	var position = target.offset().top;
    	$($.browser.safari ? 'body' : 'html').animate({scrollTop:position}, speed, 'swing');
    	return false;
   	});
	
	// オールドブラウザに対してアラートを表示
	// $("#oldbrowser").load("../oldbrowser.html");
	
	// iframe内のリンクをparentで開く
	$("#frame_update .entrylist a").attr("target","_parent");
	
});


$(function() {
	// 文字の大きさをcookieに保存
	$("#fontnav span").click(function() {
		if ($.cookie("alrFont")) {
			$.cookie("alrFont", "",{expires:-1, path:'/'});
		}// cookieを初期化
		$("#fontnav li").removeClass("selected");
		$(this).parent(0).addClass("selected");
		var fsize = $(this).attr("class");
		$("body").removeClass("small normal large").addClass(fsize);
		$.cookie("alrFont", fsize, {expires:60, path:'/'});
	});
});

// IE7fix z-index バグ対策
/*$(function() {
    var zIndexNumber = 1000;
    $('div').each(function() {
        $(this).css('zIndex', zIndexNumber);
        zIndexNumber -= 10;
    });
});
*/

// 閉じるボタンでインフォメーションボックスを消す
/*
function setRead(){
	$("#imp-info").attr("class","");
	$("#imp-info").hide("slow", function(){
		$(this).addClass("none");
	});
	$.cookie("alrRead","none",{expires:14});
}
*/
