// =============================================================================
// 背景引くためのコンテンツサイズ管理クラス
// =============================================================================
/*
   ContentsSize クラス

   最終更新日:2004年4月9日(金)
   -----------------------------------------------------------------------------

   依存
	sniffer.js
	broadcaster.js
	window.js
	window_onload.js

   -----------------------------------------------------------------------------

   コンストラクタの引数
	無し

   -----------------------------------------------------------------------------

   メソッド
	- init()
		初期化

	- onReady()
		イベント（windowからとんでくるイベント）

	- onResize()
		イベント（windowからとんでくるイベント）

	- setHeight();
		ViewPointの高さにあわせてフッターの高さを設定

	- setMinHeight( target_element_name, minHeight );
		Safariでターゲットにmin-Heightを設定

   -----------------------------------------------------------------------------

   備考
	A List Apart(http://www.alistapart.com/)とBobby van der Sluis氏の記事
	http://www.alistapart.com/articles/footers/
	を参考にしました。感謝します。

*/
// =============================================================================
if(sniffer.DOMable()) {



// -----------------------------------------------------------------------------
/*
   オブジェクト準備
*/
function ContentsSize() {
	this.contentIDs = null;
	this.margins = null;
	this.minHeights = null;

	this.init( arguments );
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   initメソッド
	Null contentsSize.init()
*/
ContentsSize.prototype.init = function( contentIDs_or_margins ) {
	this.contentIDs = new Array();
	this.margins = new Array();
	this.minHeights = new Array();
	
	for(var i=0; i<contentIDs_or_margins.length; i++) {
		if(typeof contentIDs_or_margins[i] == "number") {
			this.margins.push(contentIDs_or_margins[i]);
		}
		else {
			this.contentIDs.push(contentIDs_or_margins[i]);
		}
	}
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   メソッド
	Null contentsSize.setHeight()
*/
ContentsSize.prototype.setHeight = function() {
	var windowHeight = window.getViewPortHeight();
	if (windowHeight > 0) {
		var contentHeight = 0;
		for( var i=0; i<this.contentIDs.length; i++) {
			if((sniffer.safari() || sniffer.macIE()) && this.minHeights[this.contentIDs[i]] && document.getElementById(this.contentIDs[i]).offsetHeight < this.minHeights[this.contentIDs[i]].minHeight + this.minHeights[this.contentIDs[i]].vPadding) {
				document.getElementById(this.contentIDs[i]).style.height = this.minHeights[this.contentIDs[i]].minHeight + "px";
			}
			contentHeight += document.getElementById(this.contentIDs[i]).offsetHeight;
		}
		for( var i=0; i<this.margins.length; i++) {
			contentHeight += this.margins[i];
		}

		var contentsBodyElement = document.getElementById("contentsBody");
		var stageElement = document.getElementById("stage");
		if (windowHeight - contentHeight >= 0) {
			contentsBodyElement.style.height = stageElement.style.height = windowHeight + "px";
		}
		else {
			contentsBodyElement.style.height = stageElement.style.height = "auto";
		}
	}
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   setMinHeightメソッド
	Null contentsSize.setMinHeight( target_element_name, minHeight )

		String target_element_name		-	minHeightを設定したいエレメントのID
		Number minHeight			-	設定したいminHeight
		Number padding				-	offsetHeightと比較するので逆算にpaddingが必要
*/
ContentsSize.prototype.setMinHeight = function( target_element_name, minHeight, vPadding ) {
	this.minHeights[target_element_name] = {
		minHeight : minHeight,
		vPadding : vPadding
	};
	
	if(typeof vPadding == "undefined") {
		this.minHeights[target_element_name].vPadding = 0;
	}
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   readyイベント（windowから教えてもらえるイベント）
	Null contentsSize.onReady()
*/
ContentsSize.prototype.onReady = function() {
	this.setHeight();
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   resizeイベント（windowから教えてもらえるイベント）
	Null contentsSize.onResize()
*/
ContentsSize.prototype.onResize = function() {
	this.setHeight();
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   インスタンス化
*/
//var contentsSize = new ContentsSize();
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   windowさんにイベントを教えてもらえるようにする。
*/
//window.addListener(footer);
// -----------------------------------------------------------------------------
}