function cartboxHTML(data) {
	$('#cartBox').html(data);
}

$(document).ready(function() {
	
	$.get("/priceToggle.php", 
			function(data) {
				$('#toggle').html(data);
			}
	);
	
	$("#toggle").click(function() {
									 
		$.get("/priceToggle.php", { toggle : 'toggle' },
			function(data) {
				$('#toggle').html(data);
				window.location = document.location.href; 
			}
		);
	
	});
	
	
	Shadowbox.init({
    // skip the automatic setup again, we do this later manually
    	skipSetup: true
	});
	Shadowbox.setup('.productBlockImage a', {
					gallery:            "My Movies"
				});

	$('.thumbSwatch img').click(
		function() {
				Shadowbox.clearCache();
				
				
				var imageName = $(this).attr('alt');
				$(this).parent().parent().find('.productBlockImage img').attr("src","/images_products/small_" + imageName + ".jpg");
				$(this).parent().parent().find('.productBlockImage a').attr("href","/images_products/" + imageName + ".jpg");
				
				
				Shadowbox.setup('.productBlockImage a', {
					gallery:            "My Movies"
				});
		}
	);
	
	
	// Initialise the first and second carousel by class selector.
	// Note that they use both the same configuration options (none in this case).
	jQuery('.first-and-second-carousel').jcarousel();
	
	

	$.get("/address_finder.php",
			function(data) {
				$('#addressBlock').html(data);
			}
	);
	
	
	
	
	
	
	



	
	$('#branchSelectorTop').click(
		function() {
			
				$('#branchSelectorCenter').slideToggle('normal');
			
		}
	);
	
	var cartbox = $('#cartBox');
	cartbox.delegate('#viewCartButton', 'click', function() {
		$('#cartDetails').slideToggle('fast');
	});
	
	$.get("/quickcart.php", cartboxHTML);
	
	
	
	
	$(function() {
		$("#copy").click(function() {
			if ($('input[name=copy]').is(':checked')) {
				$("#deliveryBlock").hide('fast');
			} else {
				$("#deliveryBlock").show('fast');
				$("#custDelAddress").val('');
				$("#custDelAddress2").val('');
				$("#custDelAddressTown").val('');
				$("#custDelAddressCounty").val('');
				$("#custDelAddressPostcode").val('');
			}
		});
	});
	
});


function priceSelector($productSize, $id, $productName) {
		$.get("/product_selector.php", { productSize : $productSize, productName : $productName },
			function(data) {
				$('.optionSelector_'+$id).html(data);
			}
		);

	}
	





function addtocart($productID, $qty) {
	
		$('html, body').animate({scrollTop:0}, 'slow');
		$.get("/quickcart.php", { action : 'addtocart',productID : $productID, qty : $qty }, function(data) {
				$('#cartBox').html(data);
				$('#cartDetails').slideToggle('fast');
			});
					

	}
	
	
	
function removeItem($sessionKey) {

	$.get("/quickcart.php", { action : 'removeItem',sessionKey : $sessionKey },
		function(data) {
			var cartbox = $('#cartBox');
				cartbox.html(data);
				cartbox.find('#cartDetails').show('fast');
		}
	);
	
}


function getPostcode($postcode) {
		$.get("/address_finder.php", { postcode : $postcode },
			function(data) {
				$('#addressBlock').html(data);
			}
		);

	}
	
	
function useAddress($address) {
	$.get("/address_finder.php", { address : $address },
		function(data) {
			$('#addressBlock').html(data);
		}
	);

}

