////////////////////////////////////////////////////////////////////////////////
//
//	高さを揃える[UTF-8]
//
////////////////////////////////////////////////////////////////////////////////
(function(){
	
//
//	Acornクラス
//
var _acorn = function(_obj){
	this.obj = _obj;
	this.isIE = (document.all && !window.opera);
	this.isIE6 = (this.isIE && !window.XMLHttpRequest);
	//styleでheightが指定されているかもしれないので保存しておく
	this.defaultHeight = this.obj.style.height;
}
_acorn.prototype.getClientHeight = function(){
	return this.obj.clientHeight;
}
_acorn.prototype.resetHeight = function(){
	if(this.defaultHeight){
		this.obj.style.height = this.defaultHeight;
	}else{
		if(this.isIE){
			this.obj.style.removeAttribute("height");
		}else{
			this.obj.style.removeProperty("height");
		}
	}
}
_acorn.prototype.setHeight = function(strHeight){
	var _height = 0;
	if(this.isIE6){
		_height = strHeight;
	}else{//paddingの分を差し引く
		var paddings = this.getPaddings();
		_height = (parseInt(strHeight) - paddings);
		if(_height<0){
			_height = 0;
		}
	}
	this.obj.style.height = _height + "px";
}

//padding-topとpadding-bottomの和を返す
_acorn.prototype.getPaddings = function(){
	var paddings = 0, paddingTop = 0, paddingBottom = 0;
	
	//css + style属性
	if(this.isIE){
		paddingTop = this.obj.currentStyle.getAttribute("paddingTop");
		paddingBottom = this.obj.currentStyle.getAttribute("paddingBottom");
	}else{
		paddingTop = document.defaultView.getComputedStyle(this.obj, null).getPropertyValue("padding-top");
		paddingBottom = document.defaultView.getComputedStyle(this.obj, null).getPropertyValue("padding-bottom");
	}
	paddings = parseInt(paddingTop.replace("px", "")) + parseInt(paddingBottom.replace("px", ""));
	
	return paddings;
}

var Acorn = function(obj){
	return new _acorn(obj);
}
var toAcorns = function(objs){
	var acorns = new Array();
	for(var i=0; i<objs.length; i++){
		acorns.push(Acorn(objs[i]));
	}
	return acorns;
}



//
//	高さ調整用
//
var resize = function(objs){
	var acorns = toAcorns(objs);//ノードリストをAcornのリスト（配列）に変換
	
	var func = function(){
		for(var i=0; i<acorns.length; i++){//一度リセット
			acorns[i].resetHeight();
		}
		var getMaxHeight = function(){
			var _max = 0;
			var _height = 0;
			for(var i=0; i<acorns.length; i++){
				_height = acorns[i].getClientHeight();
				if(_max<_height){
					_max = _height;
				}
			}
			//alert(_max);
			return _max;
		}
		var max = getMaxHeight();
		for(var j=0; j<acorns.length; j++){
			acorns[j].setHeight(max);
		}
	}
	func();
	
	var fSizeChange = new OnFontSizeChange();
	fSizeChange.addEventListener("change", func);//イベント登録
}



//
//	隣同士ずつ
//
resize2 = function(objs){
	for(var i=0; i<objs.length; i+=2){
		var pair = new Array();
		if(objs[i+1]){
			pair.push(objs[i]);
			pair.push(objs[i+1]);
			resize(pair);
		}
		pair = null;
	}
}
resize4 = function(objs){
	for(var i=0; i<objs.length; i+=4){
		var pair = new Array();
		if(objs[i+1]){
			pair.push(objs[i]);
			pair.push(objs[i+1]);
			
			if(objs[i+2]){
				pair.push(objs[i+2]);
			}
			if(objs[i+3]){
				pair.push(objs[i+3]);
			}
			resize(pair);
		}
		pair = null;
	}
}



})();