$( function() {
	
	$(".locking-wheel-radio-yes").change(function() {
		//alert("I want locking wheel nutz");
		$.post("/spitxml.php", {
			add2basket: 518
		}, function(xml) {
			$("basketline", xml).each(
					function() {
						var trolleyLinkID = $(this).find('trolleyitemid').text();
						alert(trolleyLinkID);
						$(".locking-nuts-linkid").val(trolleyLinkID);
						
					});
			$("baskettotal", xml).each(
					function() {
						var price = $(this).find('price').text();
						var itemcount = $(this).find('itemcount').text();
						$("#minicart-itemcount").html(itemcount);
						$("#minicart-price").html(price);
			});
		});
	});
	
	$(".locking-wheel-radio-no").change(function() {
		alert("no locking wheel nutz");
		
	});
	
// -------------------- Add item to basket --------------------	
	$("a[name*='ADD2BASKET-']").click(function(i){
		i.preventDefault();
		// $(this).html("&nbsp;&nbsp;NOW IN CART&nbsp;&nbsp;");
		$(this).html("&nbsp;&nbsp;View Cart&nbsp;&nbsp;");

		
		// target must output content-type: text/xml for IE to work
		window.addToBasketAjax = $.post("/spitxml.php", {
			add2basket: this.name.split("-")[1]
		}, function(xml) {
			$("baskettotal", xml).each(
				function() {
					var price = $(this).find('price').text();
					var itemcount = $(this).find('itemcount').text();
					$("#minicart-itemcount").html(itemcount);
					$("#minicart-price").html(price);
				});
			$("#added2basket").html('');
			$("basketline", xml).each(
					function() {
						var productadded = $(this).find('prodname').text() + '<br />';
						$("#added2basket").html($("#added2basket").html() + productadded);
						
					});
			});
		$('html, body').animate({scrollTop:0}, 'slow');
		$("#cartPopTop").html('You have added the following item(s) to your cart:');
		$("#cartPop").fadeIn();
		$('#cartPop').css('zIndex', 99999);

		//console.log($(this).is('a.add-package'));
		if ($(this).is('a.add-package')){
			$(this).hide();
			$(this).parent().append('<a class="orange-button" href="/shopping_basket">View&nbsp;Cart</a>');
		}else{
			$(this).attr("href", "/?cmd=edittrolley");
			$(this).attr("name", "view-cart-button");
			$(this).hide();
			$(this).parent().removeClass('add-to-cart-small');
			$(this).parent().addClass('added-to-cart-small');
			$(this).next().show();
		}
		if ($('.accessory-dialog').length > 0){
			$('.accessory-dialog').jqmShow();
			updateAccessoryModalCart();
		}
		
		//$("p .view-cart").show();
	});
	
	// -------------------- Add item to basket --------------------	
	$("a[name*='ADDACCESSORY-']").click(function(i){
		i.preventDefault();
		// $(this).html("&nbsp;&nbsp;NOW IN CART&nbsp;&nbsp;");
		$(this).html("&nbsp;&nbsp;In Cart&nbsp;&nbsp;");

		
		// target must output content-type: text/xml for IE to work
		$.post("/spitxml.php", {
			add2basket: this.name.split("-")[1]
		}, function(xml) {
			$("baskettotal", xml).each(
				function() {
					var price = $(this).find('price').text();
					var itemcount = $(this).find('itemcount').text();
					$("#minicart-itemcount").html(itemcount);
					$("#minicart-price").html(price);
					$("#grandTotal").html(price);
				});
			$("#added2basket").html('');
			$("basketline", xml).each(
					function() {
						var productadded = $(this).find('prodname').text() + '<br />';
						$("#added2basket").html($("#added2basket").html() + productadded);
						
					});
			});
		$("#cartPopTop").html('You have added the following item(s) to your cart:');
		$("#cartPop").fadeIn();
		$('#cartPop').css('zIndex', 99999);
		
		
		$(this).attr("name", "in-cart");
		$(this).hide();
		$(this).parent().removeClass('buyButton');
		$(this).parent().addClass('in-cart');
		$(this).css('color','#fff');
		$(this).attr("href", "/shopping_basket");
		$(this).click(function(){window.location.href='/shopping_basket';});
		$(this).show();
		
		
		//$("p .view-cart").show();
	});
	
	$("#cartPopClose").click(function(i){
		
		$("#cartPop").fadeOut();
		
	});
	$("#cont-shopping").click(function(){
		
		$("#cartPop").fadeOut();
		
	});
	
});



