// Reduces the length of admissions site feeds to a maximum number of items,
// and displays a "More…" link to reveal the rest.
// 
// Author: Eric Naeseth

// How many items should the shortened feed be reduced to?
var SHORTENED_FEED_MAX_LENGTH = 12;

jQuery(function shorten_feeds($) {
	$('ul.feed').each(function shorten_feed() {
		var me = $(this);
		var items = me.children("li");
		
		if (items.length < SHORTENED_FEED_MAX_LENGTH + 2) {
			// Don't hide any items unless we have at least two to hide.
			return;
		}
		
		var insignificant = items.slice(SHORTENED_FEED_MAX_LENGTH);
		var expand = $('<a class="expand" href="#">More&hellip;</a>');
		expand.click(function expand_shortened_feed(e) {
			insignificant.show('fast');
			$(e.target).remove();
			return false;
		});
		
		me.after(expand);
		insignificant.hide();
	});
});
