(function($){
	$.fn.extend({
		lessMore: function(options) {

			var defaults = {
			       limit: 3,
			       moreText: "More",
			       lessText: "Less",
			       numbers: true,
			       append: true,
			       moreClass: "more",
			       lessClass: "less"
			};
		
			options = $.extend(defaults, options);
			
			return this.each(function() {
		  			
				var obj = $(this);
				
				//Create references to the options
				var moreClass = options.moreClass;
				var lessClass = options.lessClass;
				var lessText = options.lessText;
	            var moreText = options.moreText;
	
				//Calculate number of rows and hide them
				var rows = obj.children();
				var quantity = rows.length - options.limit;
				rows.slice(options.limit).hide();
	
				//If "numbers" is set to true append with number of items hidden
				if(options.numbers) {
				        moreText += ' (' + quantity + ')';
				}
				
				//Only add the link if quantity of child elements exceeds the options.limit
				if(quantity > 0) {
				       var control = '<span class="'+ moreClass +'">'+ moreText +'<\/span>';
				}
				
				//Check if "append" is set to true, otherwise prepend the "control"
				if(options.append) {
				       obj.append(control);
				}
				else {
				       obj.prepend(control);
				}
				
				//Create a reference to the control
				
				var itemControl = $('.' + moreClass, obj);
				
				itemControl.click(function() {
				
			       var link = $(this);
			       var linkif = link.hasClass(moreClass);
			
			       // If rows are hidden, show them, and change our link.
			
			       if (linkif) {
			               link.removeClass(moreClass);
			               link.addClass(lessClass);
			               link.html(lessText);
			               rows.slice(options.limit).show();
			       }
			       else {
			               link.removeClass(lessClass);
			               link.addClass(moreClass);
			               link.html(moreText);
			               rows.slice(options.limit).hide();
			       }	
				});
   			});
		}
	});
})(jQuery);		

$(function(){
	
	$('#lessMore').lessMore({  
           limit: 5
	});	
});