/**
    simple jQuery plug-in that concatinates a html list element to show
	only a specified number of li's on initial view
	
	created June 2008, Ross Bruniges 
	
	called like so (with optional over-rides):
	
		$('big_list').truncate({
			init_shown : 10
		});
**/
jQuery.fn.truncate = function(settings) {
    settings = jQuery.extend({
        init_shown : 5,
        displayed_class : 'displayed',
        link_suffix : ''
    }, settings);
    var full_number = $(this).find('li').length;
    var link_text = 'Show all ' +  full_number + ' ' + settings.link_suffix;
    var expand_link = '<a href="#" class="show_all">' +  link_text + '</a>';
    /*
        error checking:
            - throw out if there are less in list than we want to hide
            - throw out if we apply to anything other than a list
    */
    if ($(this)[0].nodeName.toUpperCase() != "UL" && $(this)[0].nodeName.toUpperCase() != "OL") {
        return $(this);
    } 
    if (settings.init_shown >= full_number) {
        return $(this);
    }
    /* main function call */
    $(this).addClass('truncated')
        .find('li:lt(' + settings.init_shown +')')
        .each(function() {
            $(this).addClass(settings.displayed_class);
        })
        .end()
        .after(expand_link);
    /* adding click handler to the created anchor */
    $('a.show_all').click(function() {
        $(this).prev().toggleClass('truncated');
        if ($(this).text() == link_text) {
            $(this).text("Show less"); 
        } else {
            $(this).text(link_text);             
        }
        return false;
    });
    return $(this);
};