/**
*
* Search Topic JQAutocomplete
* version 1.0.1
* Copyright (c) 2010 velocat, www.velocat.ru
* License http://opensource.org/licenses/gpl-license.php GNU Public License
*
* Date: 2010-12-25 12:00:00 -0300 (25 Dec 2010)
*/

jQuery.noConflict();
(function($) 
{
	$(function() 
	{
		var forum_id = $("#ls_fid").val();
		$("#live_search").autocomplete(
		{		
			url:"ajax/vajax.php",
			selectFirst: true,
			minChars:2,
			extraParams: {mode:'live_search', fid:forum_id},
			showResult: function(value, data) 
				{
                	return '<span style="">' + hilight(value, $("#live_search").val())  + '</span>';
                },
			onItemSelect: function(item) 
				{
					var id = item.data[0];
					$("#live_search_id").val(id);
					goto_topic();
            	}
		});
			
		$(document).ready(function() 
		{
			goto_topic = function()
			{
				var id = $("#live_search_id").val();
				//$("#live_search").removeClass("search");
				//$("#live_search").addClass("loader");
				//$("#live_search").attr("disabled", 'disabled');
				if(id)
				{
					window.location.href = url_topic+"?t="+id;
				}
				return false;	
			}
		});
	
		hilight = function(value, term) 
		{
			return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>");
		}
	
	});
})(jQuery);	
