$().ready(function() {
	$(".basket_update_btn").hide();
	$(".basket_qty").click(function() {
		$(this).parent().children('input[type=text]').val()
		var $button = $(this);
		var oldValue = $button.parent().find("input[type=text]").val();
		if ($button.text() == "+") {
			var newVal = parseFloat(oldValue) + 1;
		} else {
			if (oldValue >= 1) {
				var newVal = parseFloat(oldValue) - 1;
			};
		};
		$button.parent().find("input[type=text]").val(newVal);
		$(this).parent().trigger("submit")
	});
	$(".basket_update").click(function() {
		$(this).parent().parent().find('form').trigger("submit");
	});
	$("#promocode_code").click(function() {
		if ($("#promocode_code").val()=="ENTER CODE") {
			$("#promocode_code").val("");
		};
	});
	$('.lightboxphoto').lightBox({});
	// validate the comment/checkout forms when submitted
	$("#customerform").validate();
	// validate the feedback form when it is submitted
	$("#feedbackform form").validate();
	$("#whatpeoplesayform form").validate();
	$("#contact_right form").validate();
	$("#newsletterform").validate();

	$("#newsletter").click(function() {
		if ($("#newsletter").attr("checked")=="") {
			$("#newslettershare").attr("checked","");
		};
	});
	$(".compgallery a").lightBox();
	$("#competitionform").submit(function() {
		if ($("#competitionform form #name").val()=="" ||$("#competitionform form #email").val()=="") {
			alert("You have not completed your name or email address");
			return false;
		};
		if ($("#competitionform form #useie").length==0) {	//firefox etc
			if ($("#competitionform form #photo").val().substr($("#competitionform form #photo").val().length-3).toLowerCase()!=="jpg") {
				alert("You must select a valid JPG file");
				return false;
			};
		} else {	//IE
			if ($("#competitionform form #photo_ie").val().substr($("#competitionform form #photo_ie").val().length-3).toLowerCase()!=="jpg") {
				alert("You must select a valid JPG file");
				return false;
			};
		};
	});
	$("#competitionform #photo").change(function() {
		$("#fakefile").val($("#photo").val());
	});

	setTimeout('advanceSlideshow(1)', 7000);
});

function advanceSlideshow(nextpicno) {
	$('#lifestyle_left').animate({ opacity: 0 }, 1000, 'easeInOutQuad', function(){
		$("#lifestyle_left").css("background-image",'url(images/flashpics/header'+nextpicno+'.jpg)');
		$('#lifestyle_left').animate({ opacity: 1 }, 1000, 'easeInOutQuad');
	});
	if(nextpicno>4) {
		nextpicno=1;
	} else {
		nextpicno=nextpicno+1;		
	};
	setTimeout('advanceSlideshow('+nextpicno+')', 7500);
};

jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	}
});