$(document).ready(function() { 

	$("#productoption").hide();
	$(".productoption").show();
		
	$("a[href$='jpg'], a[href$='gif'], a[href$='png'], a[href$='JPG']").fancybox({ 
		'transitionIn'		:	'elastic',
		'transitionOut'		:	'elastic',
		'speedIn'			:	600, 
		'speedOut'			:	200, 
		'overlayShow'		:	true 
	});


	
	if ($(".productoption").length > 0) {
	
		var startPrice;
		var endPrice;
		var endPriceTax;
	
	
		$(".productoption span").each(function(e){
	
			startPrice = parseFloat($(this).attr("rel").replace("€","").replace(",","."));
			
			if (isNaN(startPrice)) startPrice = 0;
			
			endPrice = startPrice + parseFloat($(".price strong").html().replace("€","").replace(",","."));
			endPrice = endPrice.toFixed(2).replace(".",",") + "€";
			
			$(this).attr("rel",endPrice);
			$(this).attr("title",endPrice);
			
		});

		
		endPrice = 100 / parseInt($(".productoption span.current").html().replace("ml", "")) * parseInt($(".price strong").html().replace("€", "").replace(",", "."));
		
		$(".box_options small.price_100ml span").html(endPrice.toFixed(2).replace(".", ","));
		
		$(".box_options small.price_mwst span").html((parseFloat($(".price strong").html().replace("€", "").replace(",", ".")) * 1.19).toFixed(2).replace(".", ","));
		
		
		$(".productoption span").live("click", function(){
		
			$(".productoption span").removeClass("current");
			
			$("#productoption").val($("#productoption option").eq(parseInt($(this).attr("class").replace("item_", ""))).val());
			
			$(this).attr("class").replace("item", "");
			$(this).addClass("current");
			
			
			startPrice = $(this).attr('rel').replace("€", "").replace(",", ".");
			
			$(".box_options small.price_100ml span").html((100 / parseInt($(".productoption span.current").html().replace("ml", "")) * startPrice).toFixed(2).replace(".", ","));
			
			
			endPrice = (startPrice * parseInt($(".quantity").val())).toFixed(2).replace(".", ",") + "€"
			
			$(".price strong").html(endPrice);
			
			$(".box_options small.price_mwst span").html((parseFloat(endPrice.replace("€", "").replace(",", ".")) * 1.19).toFixed(2).replace(".", ","));
			
		});
		
		$(".quantity").live("change", function(){
	
			startPrice = $(".productoption span.current").attr('rel').replace("€", "").replace(",", ".");
			endPrice = (startPrice * parseInt($(".quantity").val())).toFixed(2).replace(".", ",") + "€"
			
			$(".box_options small.price_mwst span").html((parseFloat(endPrice.replace("€", "").replace(",", ".")) * 1.19).toFixed(2).replace(".", ","));
			
			$(".price strong").html(endPrice);

			
		});
		
	}
		
	

	
	
});

