/*var links,lastquery='',matches=$(),results_list;

$(document).ready(function() { // onload
	$('#search_query').focus();
	$('#grade').change(initGrade);
	$('#grade').change(); // fire the change onload
	$('#search').after('<div id="quicksearch_results" style="display:none;"><strong>Are you looking for..?</strong><ul><li></li></ul>');
	results_list = $('#quicksearch_results').find('ul');		
	$('#search_query').attr('autocomplete','off').keyup(function() { // on each keypress, filter the links
		var query = $.trim($(this).val().toLowerCase().replace(/[,\-\/\s]+/g,' ').replace(/[^a-zA-Z 0-9\.]+/g,'')),subquery;
		if(query==lastquery) return; // do nothing if the query is unchanged
		results_list.html('<li></li>').parent().hide();
		if(query.indexOf(lastquery)!=0) {  // if this query is not a subset of the last query, reinitialize the matches and search on all terms
			matches = links;
			subquery = query;
		} else subquery = query.substring(query.lastIndexOf(' ')+1,query.length); // if this query is a subset of the last query, no need to search the last query's terms
		if(query.length==0) { lastquery=''; return; } // return no results if there is no query
		lastquery=query;
		$.each(subquery.split(' '),function() { // filter the result for each word in the query
			var search = this;
			matches = matches.filter(function() {
				return (' ' + $.data(this,'keywords')).indexOf(' ' + search)>=0;
			});
		});
		if(matches.length>5) return;
		else {
			results_list.empty().parent().show();
			var query_exp = new RegExp('(\\b' + query.replace(/\s/g,'|\\b') +')','ig');
			if(matches.length) $.each(matches,function() { results_list.append('<li><a href="'+$(this).attr('href')+'">'+(' ' + $(this).text()).replace(query_exp,'<span class="highlight">$1</span>')+'</a> <span class="notes">('+($.data(this,'grade') ? $.data(this,'grade') + ', ' : '')+$.data(this,'domain')+')</span></li>'); });
			else results_list.html('<li></li>').parent().hide();
		}
	});
});*/

function initGrade() { // get grade content and initialize the instant search
	$('#instant_search').load('?livewhale=ajax&function=doOUSDShowBrowserTree&grade=' + $(this).val().replace(' ','%20'),function() {
		matches = links = $('#instant_search #browser .standard span a,#instant_search #browser .substandard span a').each(function() {
			$.data(this,'keywords',(this.innerHTML).toLowerCase().replace(/[,\-\/\s]+/g,' ').replace(/[^a-zA-Z 0-9\.]+/g,''));
			$.data(this,'domain',$(this).parents('.domain').eq(0).find('h5').text());
			$.data(this,'grade',$(this).parents('.grade').eq(0).find('h4').text());
		}); // grab links, attach data to match against
		// now that the grade has changed, re-fire the search:
		lastquery='';
		$('#search_query').keyup(); 
	});
}