$(document).ready(function(){
	
	$(".product_menu").each(function(){
		/* Hide the question-mark from empty units */
		var elm = $(this).find("ul li:first");
		if($.trim($(elm).find("span").html()) == ""){
			$(elm).find("img").hide()
		}
	})
	
	$("#authenticate").submit(function(){
		var href = $(this).attr("action");
		var str = $(this).serialize();
		$.ajax({
			type: "POST",
			url: href,
			data: str,
			dataType: "json",
			success:function(msg){
				if(msg.status == 0){
					$(".error").stop(false, false).slideUp().slideDown();
				}else{
					document.location.href =  msg.redirect;
					/*
					var n_html = $(".login_ok").html();
					$(".error").stop(false, false).slideUp(function(){
						$(this).html(n_html).slideDown();
					});
					*/
				}
			}
			
		})
		return false;
	})
	
	$(".add_to_cart").click(function(){
		$(this).parent().parent().parent().prev().find(".amount").slideDown(200);
		return false;
	})
	
	$(".frm_amount").change(function(){
		var href = $(this).val();
		var elm = $(this);
		$.ajax({
			url: href,
			dataType:"json",
			success:function(data){
				$(elm).parent().slideUp(200, function(){
					$("#cart_contents").html(data.amount + " producten");
					$(elm).val(0)
				})
			}
		})
	})
	
	$("#subgroups ul li").click(function(){
		var href = $(this).find("a").attr("href");
		document.location = href;
	})
	
	$(".show_warning").live("click", function(){
		$(this).parent().parent().parent().parent().find(".warning").slideToggle();
		return false;
	})
	
	$(".show_ingredients").live("click", function(){
		$(this).parent().parent().parent().prev().find(".ingredients").slideToggle();
		return false;
	})
	
	$(".show_info").live("click", function(){
		$(this).parent().parent().parent().parent().find(".catalogue_sub").slideToggle();
		return false;
	})
	$(".catalogue_sub").each(function(){
		var children = $(this).find("ul").size();
		if(children == 0){
			var info = $(this).prev().find(".show_info").parent().hide();
		}
	})
})
