$.namespace("lgp_basket", 
{
	/*
	// Assigns all links in the basket page - delete and edit etc
	*/
	assignBasketLinks : function()
	{
		$('div.basketproducts table span.btn_amend').click(function(evt)
		{
			evt.preventDefault();

			// What image_id does this product refer to?  Get it from the ID of the parent div.basketitem.
			var image_id = $(this).parents("div.basketitem").attr("id");
			
			// it's in the format image_x, so chop
			image_id = image_id.substr(6);
		
			$.fn.colorbox({href:'/matrix/' + image_id, width:"800px"}); 

			$().unbind("cbox_complete");
			$().unbind("cbox_closed");

			$().bind('cbox_complete', function()
			{
					$().lgp_browse.assignProductMatrix(image_id);
					$('.productbox').corner();
			});	
			$().bind('cbox_closed', function()
			{
					window.location.reload();
			});	
				
		}
		);
		$('div.basketproducts table span.btn_delete').click(function(evt)
		{
			evt.preventDefault();

			// What image_id does this product refer to?  Get it from the ID of the parent div.basketitem.
			var image_id = $(this).parents("div.basketitem").attr("id");
			
			// it's in the format image_x, so chop
			image_id = image_id.substr(6);
	
			// Remove this item on the server
			$.post('/ajax/basket_remove_item/', {"image_id": image_id});
				
			// find the parent called div.basketitem, and hide it
			$(this).parents("div.basketitem").hide(400, function()
			{
				// once complete, remove it from the window and update total cost
				$(this).remove();
		
				// Update Cost
				$().lgp_basket.updateTotalCost();
			});					
		}
		);
	},

	/* Iterate through all span.totalmoney - sum them up and populate span#grandtotal with the value.  Returns
	value also.*/
	updateTotalCost: function()
	{
		var iTotalCost = 0;
		$('span.totalmoney').each(function()
		{
			// trash the pound sign and add it to the totalcost.
			iTotalCost += parseFloat( $(this).html().substr(1) );
		});

		$('span#totalmoney').html('&pound;' + iTotalCost.toFixed(2));
		
		// Show or hide the continue option - obviously cant continue if nothing in basket.
		if (iTotalCost > 0)
			$('div#paypalcontinue').show();
		else
			$('div#paypalcontinue').hide();
		return iTotalCost;
	}
});
