
var arrBasket = new Array();

$(document).ready(function() {
	GetBasket();
});

function GetBasket()
{
	$.getJSON("/2e/basket.aspx",
		function(json) {
			$.each(json.Basket.items, function(i,item){
				arrBasket.push({
					"productid": item.productid,
					"qty": item.qty,
					"productname": item.productname,
					"img_src": item.img_src,
					"img_alt": item.img_alt,
					"price": item.priceexvat
				});
			});

			ShowBasket();
		});
}

function ShowBasket()
{
	var el = $("#pageViwer_basket2_div");
	if (arrBasket.length > 0)
	{
		var sHtml = "";
		var subtotal = 0;
		for (var i = 0; i < arrBasket.length; i++)
		{
			sHtml = sHtml + "<div class='Basket_display_product' style='clear:both;'>";
			sHtml = sHtml + "<img class='basket_thumbnail' src='/vShop/data/images/smallthumb/" + arrBasket[i]["img_src"] + "' width='60' height='60' alt='" + arrBasket[i]["img_alt"]  + "' />";
			sHtml = sHtml + "<div class='basket_details'>";
			sHtml = sHtml + "<span class='colorgrey'>" + arrBasket[i]["productname"] + " - Qty: </span>" + arrBasket[i]["qty"] + "<br />";
			var item_subtotal = (arrBasket[i]["price"] * arrBasket[i]["qty"]);
			sHtml = sHtml + "Subtotal: &pound;" + item_subtotal + "</div></div>";
			subtotal += (arrBasket[i]["price"] * arrBasket[i]["qty"]);
		}
		sHtml = sHtml + "<div class='basket_total'><span class='colorgrey'>Subtotal: &pound;" + subtotal.toFixed(2) + "</span></div>";
		el.html(sHtml);
	}
	else
	{
		el.html("<span class='colorgrey'>There are no items in your basket.</span>");
	}
}

