/* Ajax Search */
	jQuery.fn.fancySearch = function() {
		  return this.each(function(){
				var theForm = $(this);
				
				$("input[type=text]",theForm).autocomplete(
					theForm.attr('action'),
					{
						extraParams: getExtraParams(),
						width: '400px',
						scrollHeight: '300px',
						scroll: false,
						minChars: '1',
						max: 30,
						delay: 200,
						matchSubset: false,
						selectFirst: false,
						offsetTop: 5,
						offsetLeft: -228,
						formatItem: function(row, i, max) {
							return ((row.type != "title") ? "" : "")+(row.name_formatted?row.name_formatted:row.name);
						},
						formatResult: function(row) {
							return row.name;
						},
						formatMore: function(term) {
							return "See all results";
						},
						formatCat: function(row) {
							return '<span class="ac_cat">'+row.name+"</span>";
						}
					}
				).result(function(event, item) {
					  location.href = item.href;
				});

				function getExtraParams() {
					// get all the inputs into an array.
				    var $inputs = $(':input',theForm);

				    // not sure if you wanted this, but I thought I'd add it.
				    // get an associative array of just the values.
				    var values = {ajax:1};
				    $inputs.each(function() {
				        values[this.name] = $(this).val();
				    });
				    return values;
				}
		  }
		 )
	};
	
	$(function()
			{
				$('form[name="qsForm"]').fancySearch();
			});