$(function(){
	
	$("a#photo_big").fancybox();
	
	$("#customer_products").load("/basket/customer_products_all/");
	$("#basket").load("/basket/");
	
	$("form#basket_add").ajaxForm({
		type: 'post',
		success: function() {
			$("form#basket_add > input[name=quantity]").val('1');
			$("#basket").load("/basket/");
		},
		error: error
	});
	
	$("#calculate").click(function(){
		var opt = {
			url: '/basket/update/',
			type: 'post'
		};
		$(this).ajaxForm(opt);
		return false;
	});
	
	$("#сheckout").click(function(){
		/*
		var opt = {
			url: '/basket/insert/',
			type: 'post'
		};
		$(this).ajaxForm(opt);
		*/
		alert("Ok");
		return false;
	});
	
	$("#customer_basket_update").ajaxForm({
		type: 'post',
		url: '/basket/update/',
		success: function() {
			console.log(data.data);
			//$("#customer_products").load("/basket/customer_products_all/");
			$("#customer_products").load('fsdgsd');
		},
		error: error
	});
	
	$("a#prod_del").click(function(){
		//
	});
	
	$("#loading").ajaxStart(function(){
		$("#loading").css("height", $("#page").height() + 100);
		$(this).show();
	});
	
	$("#loading").ajaxStop(function(){
		$(this).hide();
	});
	
	function success(data, status) {
		//alert("Status ok " + data);
		console.log(data.data);
		console.log(data.post);
		console.log(status);
		//window.location = window.location.href;
	}
	
	function error(xhr, status, thr) {
		//alert("Status error");
		console.log(xhr);
		console.log(status);
		console.log(thr);
	}
	
});

function form() {
	var form = ['<form method="POST" action="/basket/order/">',
				'<input type="text" name="test1" />',
				'<input type="text" name="test2" />',
				'<input type="submit" name="tests" values="Submit" />',
				'</form>'
			   ];
	return form.join("");
}

