/**
 * jQuery plugin for cut long text.
 * @author Alex Jilkin
 */
(function($)
{
	$.fn.showmore = function(options)
	{
		options = $.extend({}, $.fn.showmore.defaults, options);

		return this.each(function(){

			if(($(this).height() - 10) > options.height)
			{
				var more = $("<div class='show-more-foot'><span class='show-more-arrow'></span><strong>" +
						options.moreText + "</strong></div>").data("_self", this).click(function(){

					var self = $(this).data("_self");

					if($(self).hasClass("show-more-open"))
					{
						$(self).removeClass("show-more-open").animate({height:options.height});
						$(this).removeClass("show-more-foot-open").hide();
						$("strong", this).text(options.moreText);
						$(this).fadeIn();
					}
					else
					{
						$(self).addClass("show-more-open").animate({height:$(self).data("_height")});
						$(this).addClass("show-more-foot-open").hide();
						$("strong", this).text(options.lessText);
						$(self).slideDown();
						$(this).fadeIn();
					}
				});

				$(this).data("_height", $(this).height())
					.addClass('show-more')
					.css({height: options.height, overflow: "hidden"})
					.after(more);
			}
		});
	};

	$.fn.showmore.defaults = {
		moreText: "Show More",
		lessText: "Show Less",
		height: 65
	};

})(jQuery);
