$(document).ready(function(){
	
	$("#search_field").keyup(function(n){
		
		txt = $("#search_field").val();
		if (txt.length > 2){
			$.getJSON(
				"/ajax/search.php?q="+txt+"&type=json",
				function(data){
					//alert(data);
					if (parseInt(data.count) > 0){
						
						$(".search_results").show();
						$(".search_results ul").html('');
						$.each(data.items, function(i,item){
							$("<li><img src=\'"+item.img+"\' width='50px'><div class='intext'><b>"+item.name+"</b><p>"+item.description.replace(",", ", ")+" <a href='/shop/w/Item/"+item.id+"/'>Подробнее.</a></p></div><div class='clearfloat'></div><div class='ft'><b>"+item.cost+"$</b></div></li>").appendTo(".search_results ul");
						});
					}else{
						$(".search_results").hide();
					}
				}
			);
		}else{
			$(".search_results").hide();
		}
		n.preventDefault();
	});
	
	$(".buy-btn").click(function(){
	
		href = $(this).attr('href');

		$.get(href, function(data){
			$.colorbox({close:'Закрыть', html:'<h2>Товар добавлен в корзину.</h2>', onComplete:function(){handle_timer=setTimeout('CloseColorBox();', 1500);}}); 
			$("#cart_count_item").html('('+data+')');
		});
	
		return false;
	});
	

	
});
	var handle_timer = 0;
	function CloseColorBox(){
		$.colorbox.close();
		clearTimeout(handle_timer);
		
	}
