/* showMore v1.0 plugin Copyright (c) 2011, Jacob Peter Fennell (http://www.jacobfennell.com)
 * Licsensed under the MIT License (http://www.opensource.org/licenses/mit-license.php)
 * In essence, you are free to use and redistribute, just keep this copyright header with it.
*/
(function($){
  $.fn.showMore = function() {
		var originalHeight = $(this).height();
		var childHeight = $(this).children().first().height();
		/*// debugging
		alert ("element:" + $(this).attr('class') + "\nChild: " +
		$(this).children().first().attr('class') + "\nChildHeight:"+childHeight);
		*/
		if (childHeight > (originalHeight + 6)){	// We don't add an extend button if it is simply paragraph overflow
			var originalTop = parseInt($(this).css('top').split('px')[0]);
			var moveTop = originalTop - childHeight - 36 + originalHeight;
			var moveHeight = childHeight + 33;
			$(this).append('<button class="showMore" style="position:absolute;left:auto;top:auto;right:0px;bottom:0px">^ expand ^</button>');
			$(this).append('<button class="minimize" style="position:absolute;left:0px;top:auto;bottom:0px"> minimize </button>');
			var btnMinimize = $(this).children('.minimize');
			var btnShow = $(this).children('.showMore');
			btnMinimize.hide();
        	btnShow.mouseenter(function() {
				btnShow.hide();
				btnMinimize.show();
				$(this).parent().css({'background-color':'rgba(255,255,255,.85)','height':moveHeight, 'top':moveTop, 'padding-top':'4px'});
         });
			btnMinimize.mouseenter(function(){
				btnMinimize.hide();
				btnShow.show();
				$(this).parent().css({'background-color':'rgba(255,255,255,0)','height':originalHeight+'px','top':originalTop+'px','padding-top':'0px'});
			});
		}
  };
})( jQuery );
