<!--

$nga(document).ready( function() {
	// do middle vertical alignment
	vAlignUpdate( '.cp_question', '.cp_label, .cp_field', '.cp_alignMiddleField', vAlignMiddleTopMarginFromMaxHeight);

	// do bottom vertical alignment
	vAlignUpdate( '.cp_question', '.cp_label, .cp_field', '.cp_alignBottomField', vAlignBottomTopMarginFromMaxHeight);
}); 

function vAlignUpdate( containerString, childrenString, alignmentClass, topMarginFunction ) {
	
	$nga( containerString ).each( function() {
		var maxHeight = 0;
		var height;
		
		// make the container visible first so heights are correct
		var parentDisplay = $nga(this).css('display');
		if( parentDisplay == 'none' ){
			$nga(this).css('display', 'block');
		}
		
		// Get the maximum height of the child classes
		$nga(this).find( childrenString ).each( function( ) {
			height = $nga(this).height();
			if ( maxHeight < height ) {
				maxHeight = height;
			}
			//alert('maxheight = ' + maxHeight);
		});
		$nga(this).find( alignmentClass ).each( function( ) {
			var oldHeight = $nga(this).height();
			if (oldHeight < maxHeight) {
				var topmargin = topMarginFunction( maxHeight, oldHeight );
				$nga(this).css('margin-top', topmargin );
			}
		});	
		
		// reset the display property for the parent
		$nga(this).css('display', parentDisplay);
	});
}

function vAlignMiddleTopMarginFromMaxHeight(maxHeight, oldHeight) {
	return (maxHeight - oldHeight) * 0.5;
}
function vAlignBottomTopMarginFromMaxHeight(maxHeight, oldHeight) {
	return (maxHeight - oldHeight);
}

//-->

