function calculateOption(obj, price)
{
	var currentOptionPriceObj = $(obj).parents('.option-group').find('input.current-option');
	var currentOptionPrice = parseFloat(currentOptionPriceObj.val());
	var priceField1Obj =  $(obj).parents('.dynamic-price').find('.price-1 input[type=text]');
	var currentPrice = parseFloat(priceField1Obj.val().replace('£', ''));

	if ($(obj).attr('checked') == true) {
		currentPrice -= currentOptionPrice;
		currentPrice += parseFloat(price);
		currentOptionPriceObj.val(price);
		priceField1Obj.val('£' + currentPrice.toFixed(2));
		calculateSecondTier(obj);
	}
}

function calculateSecondTier(obj)
{
	var priceField1 = $(obj).parents('.dynamic-price').find('.price-1 input[type=text]');
	var priceField2 = $(obj).parents('.dynamic-price').find('.price-2 input[type=text]');
	var normalPrice = parseFloat(priceField1.val().replace('£', ''));

	if (priceField2.length > 0) {
		var discountedPrice = (normalPrice / 100) * 6;
		priceField2.val('£' + (normalPrice - discountedPrice).toFixed(2));
	}
}

$(document).ready(function() {
	
	$('.autoscroll').scrollable({circular: true}).navigator().autoscroll({
		interval: 6000		
	});

	$('.option input[type=checkbox]').click(function() {

		var price = $(this).val();
		var priceField1 = $(this).parents('.dynamic-price').find('.price-1 input[type=text]');

		var newPrice = parseFloat(priceField1.val().replace('£', ''));

		if ($(this).attr('checked') == true) {
			newPrice += parseFloat(price);
		} else {
			newPrice -= parseFloat(price);
		}

		priceField1.val('£' + newPrice.toFixed(2));

		calculateSecondTier($(this));
	});

});

function closeBasketPrompt()
{
	$('.basket-prompt').hide();
}

$(function() {

	$(".price-print").click(function() {
		$("form").addClass("do-not-print");
		$(this).parents("form").removeClass("do-not-print");
		window.print();
		return false;
	});
	
	/*if ($('.basket-prompt').length > 0) {
		$('.basket-prompt').delay(5000).fadeOut(400);
	}*/
	
	$('#branches .cycle').cycle({ 
	    cleartype:  1,
	    speed: 1000,
	    speedIn: 400,
	    speedOut: 400
	});
	
	$("#nav li").hover(function(event) {
		
		$(this).find('ul:first').show();
		$(this).find('ul:first').parent().addClass("sel");
		
	}, function(event) {
		
		$(this).find('ul:first').hide();
		$(this).find('ul:first').parent().removeClass("sel");
		
	});

});


$(document).ready(function(){
	$('input.warranty').change(function(event){
		event.preventDefault();
		$(this).removeAttr('checked');

		myParent = $(this).parents('.dynamic-price');

		var oldPrice = $('input.warranty:checked', myParent).val();
		var priceField1 = $(this).parents('.dynamic-price').find('.price-1 input[type=text]');
		var newPrice = parseFloat(priceField1.val().replace('£', ''));
		newPrice -= parseFloat(oldPrice);

		$('input.warranty', myParent).removeAttr('checked');

		$(this).attr('checked', 'checked');

		priceField1.val('£' + newPrice.toFixed(2));
	});
});
