$(document).ready(function() {
	$("#command").focus();
	
	$("#command_go").mouseover(function()
	{
		$(this).removeClass("button_go");
		$(this).addClass("button_go_over");
	});
	
	$("#command_go").mouseout(function()
	{
		$(this).removeClass("button_go_over");
		$(this).addClass("button_go");
	});
	
	
	$("#auto_container").mouseover(function()
	{
		RestoreCommands();
	});
	
	$("#auto_container").mouseout(function()
	{
		CloseCommandMoreInit();
	}); 
	
	
	$("#command").keyup(function()
	{
		GrabCommands(this.value);
	});
	
	$("#command").mouseover(function()
	{
	
		$("#command").focus();
		RestoreCommands();
		GrabCommands($(this).val());
	});
	
	$("#command").mouseout(function()
	{
		CloseCommandMoreInit();
	});
	
	$("#browser_plugin_image").mouseover(function()
	{
		$(this).attr({src : "/global/images/iknowgo_browser_plugin_over.gif"});
	});
	$("#browser_plugin_image").mouseout(function()
	{
		$(this).attr({src : "/global/images/iknowgo_browser_plugin.gif"});
	});
});
		
		


function InstallIknowgoPlugin()
{
 if (window.external && ("AddSearchProvider" in window.external)) {
   // Firefox 2 and IE 7, OpenSearch
   window.external.AddSearchProvider("http://www.iknowgo.com/plugin/iknowgo.xml");
 } else if (window.sidebar && ("addSearchEngine" in window.sidebar)) {
   // Firefox <= 1.5, Sherlock
   window.sidebar.addSearchEngine("http://www.iknowgo.com/plugin/iknowgo.src",
                                  "http://www.iknowgo.com/plugin/iknowgo.png",
                                  "Search Plugin", "");
 } else {
   // No search engine support (IE 6, Opera, etc).
   alert("No search engine support.  Use FF, IE7.");
 }
}




function GrabCommands(command)
{
	//var command = document.getElementById('command').value;
	if (command=="") {
		document.getElementById("auto_container").style.display = "none";
	} else {
		var ajaxRequest;  // The variable that makes Ajax possible!
		
		try{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Something went wrong
					alert("Your browser broke!");
					return false;
				}
			}
		}
		// Create a function that will receive data sent from the server
		ajaxRequest.onreadystatechange = function(){
			if(ajaxRequest.readyState == 4)
			{
				$("#auto_container").fadeIn("slow");
				
				var ajaxDisplay = document.getElementById('command_more');
				ajaxDisplay.innerHTML = ajaxRequest.responseText;
			}
		}
		
		var queryString = "?query=" + command;
		ajaxRequest.open("GET", "/global/ajax/grab_more_commands.php" + queryString, true);
		ajaxRequest.send(null); 
	}
}


var command_more_timer;
function RestoreCommands()
{
	clearTimeout( command_more_timer );
}

function CloseCommandMoreInit()
{
	command_more_timer = setTimeout("CloseCommandMore()", 1500);
}

function CloseCommandMore()
{
	$("#auto_container").fadeOut("slow");
}