jQuery.fn.liveUpdate = function(list){
	list = jQuery(list);

	if ( list.length ) {
		var rows = list.children('li'),
			cache = rows.map(function(){
				return this.innerHTML.toLowerCase();
			});

		this
			.keyup(filter).keyup()
			.parents('form').submit(function(){
				return false;
			});
	}

	return this;

	function filter(){
		if(jQuery(this).val() != "Browse this site... Differently." ) {
			var term = jQuery.trim( jQuery(this).val().toLowerCase() ), scores = [];

			// if term letter count is greater than 15, bypass the live search
			if( term.length <= 15 )
			{
				if ( !term ) {
					rows.show();
				} else {
					rows.hide();

					cache.each(function(i){
						var score = this.score(term);
						if (score > 0) { scores.push([score, i]); }
					});

					jQuery.each(scores.sort(function(a, b){return b[0] - a[0];}), function(){
						jQuery(rows[ this[1] ]).show();
					});
				}

				// check each live search list if all elements are hidden.
				// if so, display a nice message rather than an empty list
				jQuery('div.listing').each(function() {
					if( jQuery(this).find('li:visible').length ) {
						jQuery(this).find('div.empty-item').remove();
					} else {
						jQuery(this).find('div.empty-item').remove();
						jQuery(this).append("<div class=\"empty-item\">No Results</div>");
					}
				});
			}
		}
	}
};
