jQuery.fn.stretchHeight = function (e) {
	// IFF element is shorter than main content, stretch height to match
		oh_ele = jQuery(this).outerHeight(true);
		oh_main = jQuery(e).outerHeight(true);
		h_ele = jQuery(this).height();
		//alert ("Ele: o=" + oh_ele + ", h=" + h_ele + " // Main: " + oh_main );
		if ( oh_ele < oh_main ) {
			jQuery(this).height( h_ele + (oh_main - oh_ele) );
		};
};
jQuery.fn.stretchBGD = function () {
	// IFF page content is shorter than window, stretch height to match (there's a really tall background image on the body > form that looks undesirable when cut off early)
		jQuery(this).height("auto");
		h_w = jQuery(window).height();
		h_form = jQuery(this).height();
		if ( h_form < h_w ) {
			jQuery(this).height(h_w);
		}
};
jQuery(function() {
	jQuery(".label_text, .label_img").append('<div class="cap"></div>');
	
	// add first and last classes to various elements
	jQuery("#footer ul, .subnavblock, .footlinksblock, #topnav ul").each( function() {
		jQuery(this).children("li:last").addClass("last");
		jQuery(this).children("li:first").addClass("first");
	});
	jQuery("#maintop > .skin:first, #maintop .left > .skin:first, #maintop .right > .skin:first, #mainbot .left > .skin:first, #mainbot .right > .skin:first, #maintop > .skin:first, #mainbot > .skin:first, .left > .skin:first, .right > .skin:first").each( function() {
		jQuery(this).addClass("first");
	});
	
	jQuery("td").removeAttr("nowrap");
	
	// Custom height cases
	jQuery("#rm").stretchHeight("#main");
	jQuery("#leftnav").stretchHeight("#rm");
	jQuery("body#template4 > form").stretchBGD();
});
jQuery(window).resize( function() {
	jQuery("body#template4 > form").stretchBGD();
});
