$(document).ready( function() {

	var moreVar = "More Info";
	var lessVar = "Less Info";

	$.fn.autoHeight = function(prop) {
		var temp = this.height();
		var result = this.height("auto").height();
		this.height(temp)
		return result;
	};

	//div#codes div.code_display a.more_info
	$('div.more_info_container a.more_info').toggle(function(){
		var currentHeight;
		currentHeight = $(this).parent().prev().height();
		var newHeight = $(this).parent().prev().autoHeight();
		if( currentHeight < newHeight ){
			$(this).parent().prev().animate({height:''+newHeight+''});
			$(this).text(lessVar);
		} else {
			$(this).height('auto');
			$(this).next().children().hide();
		}
		
	},function(){
		$(this).parent().prev().animate({height: '4.5em'});
		$(this).text(moreVar);
	});

	//div#codes div.code_display p.description
	$('p.shrunk_description').each(function(){
		var currentHeight;
		currentHeight = $(this).height();
		var autoHeight = $(this).autoHeight();
		if( autoHeight <= currentHeight ){
			$(this).height('auto');
			$(this).next().children().hide();
		} else {
			$(this).height('4.5em');
		}
	});
	
});
