« Return

/*
* BCDC.US - Bexpander jQuery plugin
* Examples and documentation at: http://bcdc.us
*
* This Version 1.0 ( Aug-01-2011 )
*
* Copyright (c) 2009 Bruno Correia
* Requires: jQuery v1.3+
*
* Demo at http://bcdc.us/jquery.plugins/jquery.bexpander/demo.html
*
*/

(function($) {
	$.fn.Bexpander = function(customOptions) {

		var options = $.extend({},$.fn.Bexpander.defaultOptions, customOptions); 
		var _contanier = $(this);
		$('<a class="' + options._class + '" href="#">' + options.expand_txt + '</a>').insertAfter(_contanier);
		$(_contanier + 'p:last-child').css({ 'margin-bottom' : '0' });
		
			$('a.' + options._class).toggle(function(event) {
				event.preventDefault();

				o_height = $(this).prev(_contanier).height();
				height = 0, padding = 0;
		
				$(this).prev(_contanier).children().each(function() {
					padding += parseInt($(this).css('margin-bottom'));
					height += $(this).height();
				});

				expand = $(this); // set this
				$(this).prev(_contanier).animate({ height: (height + padding) }, options.speed, function(){ 
					expand.html(options.close_txt); 
				});

			}, function() {		
				expand = $(this); // reset this
				expand.html(options.expand_txt);
				$(this).prev(_contanier).animate({ height: o_height }, options.speed);
			});
	};

$.fn.Bexpander.defaultOptions = {
	_class: 'expand', // a tag desired class name
	speed: 'normal', // animation speed
	expand_txt: 'read more', // a tag text
	close_txt: 'close' // a tag text
};

})(jQuery);