	var currAutoSuggestItem = -1;

	$(document).ready (function() {
		
		$("#search_keyword").keyup(function(event) {
			var key = event.keyCode;

			
			if(this.value.length == 0) {
				// Hide the suggestion box.
				$('#suggestions').hide();
			} 
			else if(key == 38 || key == 40) 
			{
				var autoSuggestItems = $('li', $('#autoSuggestionsList'));
				
				switch(key)
				{
					case 38:
					
						if(currAutoSuggestItem > 0)
							currAutoSuggestItem--;		
						break;				
					case 40:
						if(currAutoSuggestItem < autoSuggestItems.size()-1)
							currAutoSuggestItem++;
						break;
				}
				
				autoSuggestItems.each(function(i) {
					if(i == currAutoSuggestItem)
					{
						this.className = "over";
								
						var str =  this.innerHTML.substring(0, this.innerHTML.indexOf("(")-1) ;
						str = str.replace("<b>","");
						str = str.replace("</b>","");
						str = str.replace("<B>","");
						str = str.replace("</B>","");
																						
						$("#search_keyword").val(str);

					}
					else
					{
						this.className = "";
					}
				});
				
			}
			else if (key == 13)  // HIT ENTER
			{
				setTimeout("$('#suggestions').hide();", 200);
				search_start(document.getElementById('myform'), 1);
				
				
				$("#tipsPanel").slideUp("slow", function() {
					$("#tips").html("Show Search Tips");										 
														 
				});
						
				
		
				
				return;
			}
			else if( (key == 222)  || (key >= 65 && key <= 90) || (key >= 97 && key <= 122) || (key == 8)  )
			{
				
				$("#search_keyword")[0].className = "autocomplete_text_busy";
				
				$.post("http://www.uta.edu/research/collaborate/UTS/autocompleteSeach.php", {queryString: this.value}, function(data){
									   
					if(data.length >0) {
						$('#suggestions').show();
						$('#autoSuggestionsList').html(data);
						currAutoSuggestItem = -1;
						
						var str = $('#search_keyword').val();
						
						$("#autoSuggestionsList").find("li").each(function ()
						{
						
							this.innerHTML = this.innerHTML.replace(str,"<b>"+str+"</b>");
						
						});
						
						
					}
					else
					{
						$('#suggestions').hide();
					}
					setTimeout(function () {$("#search_keyword")[0].className = "autocomplete_text"},500);	
				});

			}
		});
	});
	
	
	
	function fill(thisValue) {
		$('#search_keyword').val(thisValue);
		setTimeout("$('#suggestions').hide();", 200);
		
		search_start(document.getElementById('myform'), 1);
		$("#tipsPanel").slideUp("slow");
		
	}

