$(document).ready(function(){
	$("form.addtobasketform").submit(function(){
		$(this).parent().find("div.error").remove();
		var option = $(this).find("select[name='productOptionId'] option:selected").val();
		if(option == "") {
			var errormarkup = '<div class="error fademe" style="display:none">Please select an option from the dropdown menu</div>';
			$(this).before(errormarkup);
			$("div.fademe").fadeIn(500).removeClass("fademe");
			return false;
		}
	});
	
	if ($("select[name='productOptionId']").length > 0) {		
		$("select[name='productOptionId']").each(function(){
			var selectedclass = $(this).find("option:selected").attr("class");	
			if ($("input[name='" + selectedclass + "']").length > 0) {
				var pricetoset = $("input[name='" + selectedclass + "']").val();
				$(this).parents("form:first").find("div.the-price").html("&pound;" + parseFloat(pricetoset).toFixed(2));
			}
		});
		
		$("select[name='productOptionId']").change(function(){
			var selectedclass = $(this).find("option:selected").attr("class");			
			if ($("input[name='" + selectedclass + "']").length > 0) {
				var pricetoset = $("input[name='" + selectedclass + "']").val();
				$(this).parents("form:first").find("div.the-price").html("&pound;" + parseFloat(pricetoset).toFixed(2));
			}
		});
	}
	
	$("a.newwindow").click(function() {
		window.open(this.href);
		return false;
	});
	
	$(function() {
		$(".footer-carousel").jcarousel({
			visible: 5,
			scroll: 1,
			animation: 500,
			wrap: "circular"
		});
	});
});
