$(document).ready( function() {

	
	// match column heights
	addLoadEvent(function() {
		$(".content, .sidebar").matchColumns();
	});	
	
	// twice because of some IE bugs
	if($.browser.msie){
		$(".content, .sidebar").matchColumns();
	}
	

});

jQuery.fn.matchColumns = function(){

	var height_tar = 0;
	
	$(this).each(function(){
		height_obj = (this.offsetHeight) ? this.offsetHeight : this.pixelHeight;
		height_tar = Math.max(height_tar, height_obj);
	});
	
	$(this).each( function() {
	   //var prefix = ($.browser.msie && $.browser.version < 7) ? 'height' : 'min-height';
		$(this).css({ 'height' : (height_tar)+'px' });
	});

	$('.inpad').each( function() {
		var pad_top = $(this).css('padding-top');
		var pad_bot = $(this).css('padding-bottom');
		pad_top = Number (pad_top.split('px')[0]);
		pad_bot = Number (pad_bot.split('px')[0]);
		
		var offset = pad_top + pad_bot;
		var nav_height = 0;
		
		if ( $('.nav_sub').length != 0 ) {
			nav_height = $('.nav_sub')[0].offsetHeight;
		}
		
		var new_height = ( $(this).parents('.content').length != 0 ) ? height_tar-offset-nav_height : height_tar-offset;
		$(this).css({ 'height' : new_height+'px' });
		
	});
	
};

// onload window event
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

