﻿(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();
						
						if(sIFR)
						{
						    sIFR.replace(helvetica, {
                                            selector: 'div.blog_heading h2',
                                            css: ['.sIFR-root { background-color:none; font-size:16px; color: #ed7821;}',
                                                'a { color: #ed7821; text-decoration:none;} ',
                                                'a:hover { color:#ed7821; text-decoration:underline;} ',
                                                
                                            ]
                                            });    
						}
					}
					else {
						link.removeClass(lessClass);
						link.addClass(moreClass);
						link.html(moreText);
						rows.slice(options.limit).hide();
					}
				});
			});
		}
	});
})(jQuery);


