/*-------------------------------------------------------------------- 
 * JQuery Plugin : "SameHeight"
 *
 * version 1.1
 *
 * Author : Hiromu Hasegawa
 * Copyright (c) 2008 THE HAM MEDIA (http://h2ham.seesaa.net)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Since:     2008-11-05
 * Modified:  2008-11-15
 *
 * jQuery 1.2.6
--------------------------------------------------------------------*/

(function($){

$(function(){
	$.sameHeight();
});

//デフォルトセレクタ
$.sameHeight = function(settings) {
		c = $.extend({
			selector: '.sameHeight' //class='.sameHeight'
		}, settings);
		sameHeightFn(c.selector);
};

//ユーザー指定セレクタ(使用方法(Usage)：$('#block').sameHeight();) 
$.fn.sameHeight = function(c) {
    return this.each(function() {
        sameHeightFn(this);
    });
};

//高さの違うカラムを同じ高さにする
function sameHeightFn(c) {
	$(c).each(function(){
		//変数をセット
		var eachHeight = 0;
		var eachPaddingTop = 0;
		var eachPaddingBottom = 0;
		
		$(this).children().each(function(){

			//高さの値を取得
			var heightValue = $(this).height();
			
			//IE6用 padding-topとpadding-bottomの値を取得
			var topValue = $(this).css("padding-top");
			var bottomValue = $(this).css("padding-bottom");
			
			//文字を数値に変換
			topValue = parseFloat(topValue);
			bottomValue = parseFloat(bottomValue);
			
			//一番大きいheightの値にする
			if (heightValue > eachHeight) { eachHeight = heightValue; };
			
			//一番大きいpadding-topの値にする
			if (topValue > eachPaddingTop) { eachPaddingTop = topValue; };
			
			//一番大きいpadding-bottomの値にする
			if (bottomValue > eachPaddingBottom) { eachPaddingBottom = bottomValue; };

		});
		
		//IE6用 height + paddint-top + padding-bottomの合計値
		var total =  eachHeight + eachPaddingTop + eachPaddingBottom;
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': total}); };
		
		//IE6以外。paddingの値がそれぞれ違っても同じ高さになる。
		$(this).children().css({'min-height': eachHeight , 'padding-top':eachPaddingTop,'padding-bottom':eachPaddingBottom});
        
	});
};
})(jQuery);