$(document).ready(function(){
	//hide loader
	$("#contentLoader").hide();
	//live search timer
	var key_count_global = 0; 
	var timer;
	$("#inputString").keyup(function(){
		$('#loader').fadeIn("slow");
		key_count_global++;
		clearTimeout(timer);
		timer = setTimeout(function(){ getResults() }, 1000);
	});
	//toggle for homepage
	$("#aboutLink").click(function() { $("#about").toggle(); });
	$("#policyLink").click(function() { $("#privatePolicy").toggle(); });
	if (document.getElementById("myTable")) {
		$("#myTable").tablesorter({ 
			// sort on the first column 
			sortList: [[3,1]],
			headers: { 
				4: { 
					// disable sorting on sell it
					sorter: false 
				}
			},
			widgets: ['zebra']
		}); 
	}
});
//ajax call to get search results
function getResults(){
	$('#loader').fadeIn("slow");
	$.post("lookup.php", {queryString: ""+$("#inputString").val()+""}, function(data){ 
		$('#content').fadeOut("fast");
		$('#searchResult').html(data);
		$('#searchResult').fadeIn("slow");
		$('#loader').fadeOut("fast");
	});
}
//search for item
function clicked(itemNum, keyword){
	document.getElementById("searchResult").style.display = "none";
	document.getElementById("contentLoader").style.display = "block";
	location.href='search.php?itemnum='+itemNum+'&keyword='+keyword+'';
}
