﻿// JavaScript Document


/****************************************************/
// KOTOHIGI DESIGN
// top.js
/****************************************************/

var isOpen=false;
var initItemVal=10;
var initHeight;

$(function(){
	$("#news_more span").bind("click", moreClick);
	
	for(var i=0; i<$(".newsDate").length; i++){
		$(".newsDate").eq(i).html("- "+$(".newsDate").eq(i).html());
	}
	
	initHeight=0;
	for(var j=0; j<initItemVal; j++){
		initHeight+=$(".newsWords").eq(j).height();
	}
	$("#news_calendar_wrapper").css({height:initHeight+"px"});
	
});

function moreClick(){
	
	var goalHeight;
	if(isOpen){
		goalHeight=initHeight;
	}
	else{
		goalHeight=$("div#news_calendar").height();
		var gap=$("div#wrapper").height()-(190+50+100+goalHeight+50);
		if(gap<0){
			//alert(gap);
			var allHeight=$("div#wrapper").height()-gap;
			$("div#wrapper").css({height:allHeight+"px"});
		}
	}
	
	$("#news_calendar_wrapper").animate(
		{height:goalHeight+"px"},
		{duration:1200,
		easing:"easeInOutQuint",
		complete:function()
			{
				isOpen=!isOpen;
				if(isOpen){
					$("#news_more span").html("-> fold up");
				}
				else{
					$("#news_more span").html("-> more");
					$("div#wrapper").css({height:"100%"});
				}
			}
		}
	);
}
