$(document).ready(function(){
	
	$(".language").click(function(){
		var href = $(this).attr("href");
		$.ajax({
			type:"POST",
			url:"/ajax" + href,
			data:{"href":document.location.href},
			dataType:"json",
			success:function(msg){	
				//alert(msg.redirect)
				document.location.href = msg.redirect;
			}
		})
		return false;
	})
	
	$(".frm_amount").change(function(){
		var elm = $(this);
		var href = $(this).val();
		$.ajax({
			url: href,
			dataType: "json",
			success: function(data)
			{
				$("#cart_amount").html(data.amount);
				elm.parent().next().show(300).animate({
					left: "0" /* JUST A DUMMY */
				}, 2000, function(){
					elm.parent().next().hide(300)
				});
				elm.val(0);
			}
		})
	})
	
	$("#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;
	})
	
	$("#subgroups ul li").click(function(){
		var href = $(this).find("a").attr("href");
		document.location = href;
	})
	
	$(".show_warning").live("click", function(){
		$(this).parent().parent().parent().prev().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();
		}
	})
})
