//
//
// Similar Height Class
//
// 
// ===== usage =====
// var sh = new SimilarHeight();
// sh.addClass("foo");
//
SameHeight = function()
{
	this.els = [];
	this.minHeight = 0;
}
SameHeight.prototype = {
	addClass: function(_class)
	{
		this.classname = _class;
		this.observe(window, "load", this, this.apply);
	},
	setMinHeight: function(_height)
	{
		this.minHeight = _height;
	},
	observe: function(_el, _func, _listener, _callback)
	{
		if(_el.addEventListener)
		{
			_el.addEventListener(_func, function(e)
			{
				_callback.call(_listener, e);
				
			}, false);
		}
		else if(_el.attachEvent)
		{
			_el.attachEvent("on"+_func, function(e)
			{
				_callback.call(_listener, e);
			});
		}
	},
	apply: function()
	{
		this.els = this.getElementsByClassName(this.classname);
		var h = this.getMaxHeight();
		//
		for(var i=0,len=this.els.length; i<len; i++)
		{
			var e = this.els[i];
			e.style.height = h+"px";
		}
	},
	getMaxHeight: function()
	{
		var h = 0;
		//
		for(var i=0,len=this.els.length; i<len; i++)
		{
			var el = this.els[i];
			if(h<el.offsetHeight) h=el.offsetHeight;
		}
		if(h<this.minHeight) h=this.minHeight;
		return h;
	},
	getElementsByClassName: function(_class)
	{
		var e = [];
		var a = document.getElementsByTagName("*");
		for(var i=0,len=a.length; i<len; i++ )
		{
			if(a[i].className)
			{
				var c = a[i].className.split(" ");
				for(var j in c)
				{
					if(c[j]==_class) e.push(a[i]);
				}
			}
		}
		return e;
	}
}