///////////////////////////////////////////////////////////////////////////////
// Moms Internet Guide - Search Box AJAX Code 
// v 1.0.4
//
// Bridge Worldwide
// Ryan Olton 
//
// 02.20.2008 
///////////////////////////////////////////////////////////////////////////////

	$(document).ready(function()
	{
		// turn off the autocomplete feature
		$("#searchtext").attr("autocomplete", "off");
		
		$("#searchtext").keyup(function (e)
		{        
	        if (e.preventDefault)
			{
				e.preventDefault();
			}
			else if (e.stopPropagation)
			{
				e.stopPropagation();
			}
						
			var url = "search_popup.php";		
			
			var text = $("#searchtext").val();
			
			if (text == "")
			{
				$("#searchresults").hide();
			}
			else
			{
				$.get(url, { searchtext: text }, function(data)
				{
					// I want to point out that again IE made this more complicated that it needs to be!
					$("#searchresultsdata").html(data);
					// Since IE cannot handle right: auto; ... we have to do it by ourselves!
					var window_width = $(window).width();	
					var div_right = (window_width / 2) - 480;
					$("#searchresults").css({ right: div_right }).show();					
				});
			}
			
		});
		
		$("#searchtext").focus(function ()
		{        
	        var url = "search_popup.php";		
			
			var text = $("#searchtext").val();
			
			if (text != "")
			{	
				$.get(url, { searchtext: text }, function(data)
				{
					$("#searchresultsdata").html(data);
					var window_width = $(window).width();	
					var div_right = (window_width / 2) - 480;
					$("#searchresults").css({ right: div_right }).show();	
				});
			}
			
		});
	});
	
	$(document).ready(function()
	{
		$("#searchtext").blur(function ()
		{   
			setTimeout(function() { $("#searchresults").slideUp(250) }, 200);
		});
	});