$(function() {
////////////////////////////////////////////////////

$('#tabContainer > ul').tabs();

$("#tabContainer .tabInfo li a").click(function(){
    $("#tabContainer .none").css("display","none").css("line-height","0");
    $("#tabContainer .more").html("<a href='#'><span>さらに見る</span></a>");
 });

$("#tabContainer dl.newsList").each(function(){
	$(this).children("dt").css("display","inline").css("line-height","1.6");
	$(this).children("dd").css("display","block").css("line-height","1.6");
	var len = $(this).children("dd").length;
	if(len < 4) {
        $(this).next(".more").css("display","none").css("line-height","0");
        $(this).children("dd:last-child").css("margin-bottom","0");
    } else {
		if(len < 6) {
      	  $(this).next(".more").css("display","none").css("line-height","0");
      	  $(this).children("dd:last-child").css("margin-bottom","0");
		}
        $(this).children("dt:gt(4) , dd:gt(4)").addClass("none").css("display","none");
	}
});

$("#tabContainer .more").click(function(){

			var btn = $(this).find("a").attr("class");
			if(btn=="close") { //閉じてる時
	 			scroll();
				$(this).prev("dl").children("dt:gt(4) , dd:gt(4)").css("display","none");
				$(this).html("<a href='#'><span>さらに見る</span></a>");
            	return false;
			} else { //開いてる時
				$(this).prev("dl").children("dt").css("display","inline").css("line-height","1.6");
            	$(this).prev("dl").children("dd").css("display","block").css("line-height","1.6");
            	$(this).html("<a href='#' class='close'><span>閉じる</span></a>");
	           	return false;
			}
});

////////////////////////////////////////////////////
});

function scroll(){
	var Hash = $("#mainContents");
	var HashOffset = $(Hash).offset().top;
	setTimeout(function() {
		$("html,body").animate({
			scrollTop: HashOffset
		}, 500).queue([]);
	}, 200);
}
