$(document).ready(function(){
	$.ajaxSetup({
		url: "scripts/request.php",
		timeout: 3000,
		type: "POST",
		cache: false,
		async: true,
		contentType: "application/x-www-form-urlencoded"
	});
	$("input.add-to-cart").click(function(){
		var name = $(this).parent('div.order').children("input.name").attr('value');
		var price = $(this).parent('div.order').children("input.price").attr('value');
		var count = $(this).parent('div.order').children("input.quantity").attr('value');
		var id = $(this).parent('div.order').children("input.id_num").attr('value');
		$.ajax({
			data:"event=add&id="+id+'&name='+name+'&price='+price+'&count='+count,
			success:function(request, textStatus){
				var par = request.split('&');
				$("#count").html(par[0]);
				$("#cost").html(par[1]);
				$("#backet").css({'top':getInnerHeight()/3 + getScrollY()});
				$("#backet").show(20, function(){
					$("#backet_name").html(name);
					$("#backet").animate({'top':getInnerHeight()/4 + getScrollY()},1500,function(){$("#backet").hide(200);})
				});
			}
		});
	});

	$("input.item_del").click(function(){
		var id = $(this).attr('name');
		$.ajax({
			data:"event=del&id="+id+'&name=1&price=1&count=1',
			success:function(request, textStatus){
				document.location = 'order.html';
			}
		});
	});

	$("input.item_count").keyup(function(){
		var id = $(this).attr('name');
		var count = $(this).attr('value');
		$.ajax({
			data:"event=set&id="+id+'&name=1&price=1&count='+count,
			success:function(request, textStatus){
				document.location = 'order.html';
			}
		});
	});
});

function getScrollY() 
{
    scrollY = 0;    
    if (typeof window.pageYOffset == "number") {
        scrollY = window.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        scrollY = document.documentElement.scrollTop;
    }  else if (document.body && document.body.scrollTop) {
        scrollY = document.body.scrollTop; 
    } else if (window.scrollY) {
        scrollY = window.scrollY;
    }
    return scrollY;
}
  
function getInnerHeight()
{
    height = 0;
    if (window.innerHeight) {
        height = window.innerHeight - 18;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        height = document.documentElement.clientHeight;
    } else if (document.body && document.body.clientHeight) {
        height = document.body.clientHeight;
    }
    return height;
}

var ref = '';
function Ref(url)
{
	if (ref == '')
	{
		if (typeof url != "undefined")
		{
			ref = url;
			setTimeout("Ref()", 2000);
		}
		else return;
	}
	else document.location.href = ref;
}