$(document).ready(function(){	
	$(".link").each(function() {
		$(this).bind("mouseover", function() {		
			var id = $(this).attr("id");		
			$(this).slideUp();	
			setTimeout(function() {$("#"+id+"-hover").slideDown(); }, 200);			
		});
	});	
	$(".link-hover").each(function(index, el) {				
		$(el).bind("mouseleave", function() {				
			var id = $(this).attr("id").substr(0,7);			
			$(this).slideUp();			
			setTimeout(function() {$("#"+id).slideDown(); }, 200);		
		});
	});
});
function auth(){
	$("#errors_box").html('');
	name=$("#field_name").val();
	password=$("#field_password").val();
	if (name=='') {
		$("#errors_box").html('Поле "логин" не заполнено');
		return false;
	}
	if (password=='') {
		$("#errors_box").html('Поле "пароль" не заполнено');
		return false;
	}	
	/*
	$.ajax({
		type: 'POST',
		url: '/ajax/user.php',
		data: {
			mode:'auth',
			name:name,
			pass:password
		},
		success: function(response){
			if(response=='auth_fail')
				$("#errors_box").html('Пользователя с таким логином/паролем не существует.');
			else {
				$("#basket_block").html("<div class='basket_inn'><p class='login'>Семенов Иван Митрофанович</p><a href='/Basket' class='h2'>Корзина</a><p>Всего товаров: <a href='/Basket'>15</a> шт.</p><p>На сумму: <span>12 500 р.</span></p><form><input class='button' type='button' value='выйти' onclick='logout();'/><a href='/Cabinet' class='privat'>личный кабинет</a></form></div>");
				$("#registration").hide();
			}
		}
	});
	*/
	return true;

}
function logout(){
/*
$.ajax({
	type: 'POST',
	url: '/ajax/user.php',
	data: {mode:'logout'},
	success: function(response){
		$("#basket_block").html("<div class='basket_inn'><p class='login'>Семенов Иван Митрофанович</p><a href='/Basket' class='h2'>Корзина</a><p>Всего товаров: <a href='/Basket'>15</a> шт.</p><p>На сумму: <span>12 500 р.</span></p><form><input class='button' type='button' value='выйти' onclick='logout();'/><a href='/Cabinet' class='privat'>личный кабинет</a></form></div>");
	}
});
*/
return true;
}
function repeat(id){
  $.ajax({
		type: 'POST',
		url: '/ajax/shop.php',
		data: {mode:'repeat',id:id},
		success: function(response){
			$('#basket_block').html(response);
		}
	});
return true;
}

function buy_history(id,zid){
  
	num=$('#'+zid+'_num'+id).val();
  	$.ajax({
		type: 'POST',
		url: '/ajax/shop.php',
		data: {mode:'buy',id:id,num:num},
		success: function(response){
				$('#basket_block').html(response);
		}
	});
return true;
}


function update(id){
	num=$('#num'+id).val();
	$.ajax({
		type: 'POST',
		url: '/ajax/shop.php',
		data: {mode:'update',id:id,num:num},
		success: function(response){
                var a = response.split("#");
                var cena = parseInt(a[0]);
                if (cena>=3000) {
                    $("div.choice.dost").find("p.price").html("0 р.");
                    $('input#dost').attr("value",0);
                } else {
                    $("div.choice.dost").find("p.price").each(function(n,element){
                        $(element).html($(element).next().next().text()+' р.');
                    });                    
                }
                $("span#clear_price").text(cena);
                update_final_price();
				$('#basket_block').html(a[1]);
		}
	});
return true;
}


function update_final_price(){
    var a = parseInt($('input#opl').attr("value"));
    a = a + parseInt($('input#dost').attr("value"));
    a = a + parseInt($('span#clear_price').text());
    $("span#last_price").text(a);
}






function buy(id){
	num=$('#num'+id).val();
	$.ajax({
		type: 'POST',
		url: '/ajax/shop.php',
		data: {mode:'buy',id:id,num:num},
		success: function(response){
				$('#basket_block').html(response);
		}
	});
return true;
}

function del(id){

	num=$('#num'+id).val();
	$.ajax({
		type: 'POST',
		url: '/ajax/del.php',
		data: {mode:'del',id:id,num:num},
		//success: function(response){
		//$('#basket_block').html(response);}
	});
return true;
}
function tshow(id){
    
    $(id).toggle();
        
}
