$(document).ready(function() {
	$('#smallcart').hide();
	$datac = "type=load";
	$.ajax({
		url: "../asp/cart.php",
		type: "post",
		dataType: "json",
		data: $datac,
		timeout: 10000,
		success: function(data) {
			totalsum = 0;
			totalqty = 0;
			$("div[id^='ib']").children('.lb105').children('p.incart').hide();
			$("div[id^='ib']").children('.lb105').children('p.nocart').show();
			$("div[id^='ib']").children('.lb105').children('p').children('.store').hide();
			$.each(data, function(i, value) {
				if (i == 'CartQty') {
					$('#smallcart').hide();
				} else {
					$('#smallcart').show();
					$("div[id='ib" + value.GoodsId + "']").children('.lb105').children('p.nocart').hide();
					$("div[id='ib" + value.GoodsId + "']").children('.lb105').children('p.incart').show();
					$("div[id='ib" + value.GoodsId + "']").children('.lb105').children('p.incart').children('.qty').text(value.Quantity);
					if (value.GoodsInStore > 0) {
						$("div[id='ib" + value.GoodsId + "']").children('.lb105').children('p').children('.store').html('<br />Доступно ' + value.QuantityInStore + ' шт.');
						$("div[id='ib" + value.GoodsId + "']").children('.lb105').children('p').children('.store').show();
					};

					totalsum = totalsum + (value.PriceDiscount * value.Quantity);
					totalqty = totalqty + value.Quantity;
				};
			});
			$('#cqty').text(totalqty);
			$('#csum').text(totalsum.toFixed(0));
			if (totalsum > 0) {
				$('.basket').children('a').css('color', '#FF0000');
			} else {
				$('.basket').children('a').css('color', '#8C4129');
			};
		},
		error: function(XMLHttpRequest, textStatus, ErrorThrown) {
		}
	});
});


