var contentsOpenFlag = true;
var rootContentsHeight = 0;
var htmlMarginTop;
var resizeHandler = function() {
	$('#container').css({height:$(window).height()-htmlMarginTop+'px'})
	if (rootContentsHeight > $('#container').height() - $('header').height() - parseInt($('header').css('margin-bottom'))) {
		$('#contents').height($('#container').height() - $('header').height() - parseInt($('header').css('margin-bottom')));
	}
	if (contentsOpenFlag) {
		$('#contents').css({top:$('#container').height()-$('#contents').height()+'px'})
	} else {
		$('#contents').css({top:$('#container').height()-20+'px'})
	}
	// $('#trace').text($('#contents').height());
}

jQuery(document).ready(function() {
	$('#container').css({overflow:'hidden'});
	$('body').css({overflow:'hidden'});
	$('#contents').css({position:'absolute'})
	$('#contents').css({visibility:'hidden'})
	$('#btn_arrow').click(function(){
		if (contentsOpenFlag) {
			contentsClose();
		} else {
			contentsOpen();
		}
	});
});

function contentsClose() {
			$('#btn_arrow_dn').hide();
			$('#backgroundCaption').fadeIn();
			$('#contents').animate({top:$('#container').height()-20+'px'})
			contentsOpenFlag = false;
}
function contentsOpen() {
			$('#btn_arrow_dn').show();
			$('#backgroundCaption').hide();
			$('#contents').animate({top:$('#container').height()-$('#contents').height()+'px'})
			contentsOpenFlag = true;
}

jQuery.event.add(window, "load", function(){
	rootContentsHeight = $('#contents').height();
	htmlMarginTop = parseInt($('html').css('margin-top'));
	$('#container').css({height:$(window).height()-htmlMarginTop+'px',minHeight:'0%'})
	$('body').css({height:$('#container').height()+'px'})
	resizeHandler();
	$('#contents').css({visibility:'visible'});
	$(window).resize(resizeHandler);
});

