$(function() {
    $(".zakaz-link").each(function() {
        $(this).click(function() {
			var id = $(this).attr('id');
			$("#z"+id).toggle("slow")
			
			if ($(this).hasClass('zakaz-closed')) {
				$(this).removeClass('zakaz-closed')
				$(this).addClass('zakaz-opened')
			} else {
				$(this).removeClass('zakaz-opened')
				$(this).addClass('zakaz-closed')
			}
		})
    })
	
	$(".zakaz1").each(function() {
		$(this).hide()
	})
	
	$("#header .enter a").click( function() {
		$("#header .form").toggle("fadeIn");
	})
	$("#header .form .login input").click( function() {
		$(this).attr('value', '')
	})
	$("#header .form .password input").click( function() {
		$(this).attr('value', '')
	})
	
	$(".jCarousel").jCarouselLite({
		btnNext: ".carousel .next",
		btnPrev: ".carousel .prev",
		scroll: 1,
		visible: 4,
		mouseWheel: true,
	});
	
	$(".carousel .next").hover(function () {
		$(this).css("background-image", $(this).css("background-image").replace("-0", "-1"))
	}, function() {
		$(this).css("background-image", $(this).css("background-image").replace("-1", "-0"))
	})
	$(".carousel .prev").hover(function () {
		$(this).css("background-image", $(this).css("background-image").replace("-0", "-1"))
	}, function() {
		$(this).css("background-image", $(this).css("background-image").replace("-1", "-0"))
	})

	/*Интернет магазин*/
	$('input[name="f_BuyerType"]').change(function() {
			$('#buyerType1').hide('slow')
			$('#buyerType2').hide('slow')
			$('#buyerType3').hide('slow')
			$('#buyerType' + $(this).val()).show('slow')
	})
	
	$('input[name="f_DeliveryMethod"]').change(function() {
		if ($(this).val() != 3) {
			$('#address_field').show('slow')
		} else {
			$('#address_field').hide('slow')
		}
	})
	
	$('input[name="f_BuyerType"]:checked').trigger('change')
	$('input[name="f_DeliveryMethod"]:checked').trigger('change')
	
	// Вешаем обработчики изменений на контактные/информационные поля
	$('input[name="f_ContactName"]').change(function() {
		displaySaveContactInfoBlock()
	})
	$('input[name="f_Phone"]').change(function() {
		displaySaveContactInfoBlock()
	})
	$('textarea[name="f_Address"]').change(function() {
		displaySaveContactInfoBlock()
	})
	$('input[name="f_Email"]').change(function() {
		displaySaveContactInfoBlock()
	})
	$('input[name="f_PaymentMethod"]').change(function() {
		displaySaveContactInfoBlock()
	})
	$('input[name="f_DeliveryMethod"]').change(function() {
		displaySaveContactInfoBlock();
		$('textarea[name="f_Address"]').val($('#'+$(this).attr('id')+'-text').html());
	})
	$('input[name="f_BuyerType"]').change(function() {
		displaySaveContactInfoBlock()
	})
	$('#buyerType1 input').each(function() {
		$(this).change(function() {
			displaySaveContactInfoBlock()
		})
	})
	$('#buyerType2 input').each(function() {
		$(this).change(function() {
			displaySaveContactInfoBlock()
		})
	})
	$('#buyerType3 input').each(function() {
		$(this).change(function() {
			displaySaveContactInfoBlock()
		})
	})
	
	
	function displaySaveContactInfoBlock()
	{
		$("#saveContactInfoBlock").show("slow");
	}
});

