// All praise be to jQuery
$(function() {

	$("#errorMessage").hide();
	$("#noticeMessage").hide();

	$("#blogArchive li a").click(function()
	{
		$(this).siblings("ul").toggleClass("hideMe");
	});
	
	$("#loginLink").click(function(e) {
		e.preventDefault();
		$("#loginForm").submit();
	});
	$("#newsletterSubscribeLink").click(function(e) {
		e.preventDefault();
		alert("Subscribe to newsletter here....");
	});

	// Cart quantity update
	$("#updateCart").click(function(e) {
		e.preventDefault();
		$("#cartForm").submit();
	});

	// Cart item removal
	$(".removeItemFromCart").click(function(e) {
		e.preventDefault();
		$($(this).siblings("input")[0]).val(0);
		$("#cartForm").submit();
	});

	// Checkout, accordian information display for Postage Options
	$("#postageOptions,#paymentOptions").find("input[type=radio]").each(function() {
		$(this).click(function() {
			$("#postageOptions,#paymentOptions").find("input[type=radio]").each(function() {
				$(this).parent().siblings("div").slideUp(200);
			});			
			$(this).parent().siblings("div").slideDown(200);
		});
	});
	$("#sameAsAbove").click(function() {
		if ($(this).attr('checked')) {
			//$("#deliveryAddressDetails").slideUp(200);
			$("input[type=text],select").each(function() {
				if ($(this).attr("rev")) {
					$(this).val($("input[name="+$(this).attr("rev")+"]").val());
				}
			});
		}
		else {
			//$("#deliveryAddressDetails").slideDown(200);
		}
	});
	
	$('.otherSelect').change(function(){

		if($(this).val() == 'other') {
			$($(this).attr('rel')).show();
		} else {
			$($(this).attr('rel')).hide();
		}
	});
	
	$('.slideshow').cycle({
		fx: 'fade',
		random: 0,
		speed: 12000
	});

});
