
$(document).ready(function() {

	$('#manufacturer_search_div').show();
	$('#manufacturer_search_div input').val('');

	//filter results based on query
	function filter(selector, query) {
	  query	=	$.trim(query); //trim white space
	  query = query.replace(/ /gi, '|'); //add OR for regex query

	  $(selector).each(function() {
		($(this).text().search(new RegExp(query, "i")) < 0) ? $(this).hide() : $(this).show();
	  });
	}

/*
	//filter results based on query
	function filter(selector, query) {
	  query	=	$.trim(query); //trim white space
	  query = query.replace(/ /gi, '|'); //add OR for regex query
	  
	  $(selector).each(function() {
	//	if (!$(this).hasClass('original')) {
			var text = $(this).text();
			($(this).text();.search(new RegExp(query, "i")) < 0) ? $(this).hide() : $(this).show(); /*.html($(this).next().text())
														.html(text.substring(0, text.search(new RegExp(query, "i")) - 1) 
														+ "<span class='search_highlight'>" 
														+ text.substring(text.search(new RegExp(query, "i")), query.length)
														+ "</span>" + text.substring(query.length)
														+ " start: " + text.search(new RegExp(query, "i")) - 1
														+ ", end: " + query.length); 
	//	}
	  });
	  //alert(query);
	}
*/
	//alert('ready');

	//from here: http://net.tutsplus.com/tutorials/javascript-ajax/using-jquery-to-manipulate-and-filter-data/
	$('#manufacturer_search').keyup(function(event) {  
	   
		//alert('pwn');
		
		 //if esc is pressed
		 if (event.keyCode == 27) {  
		   $(this).val('');  
		 }
	
		//make everything visible if the query is empty
		if ($(this).val() == '') {
			$('#categories_list p, #manufacturers_list p').show();
		}
	   
		 //if there is text, filter  
		 else {  
		   filter('#categories_list p, #manufacturers_list p', $(this).val());  
		 } 
	});
	 
});

//alert('after ready');