$(function() {
	
	$('#call_me').click(function(){
		if ($(this).text() == 'Обратный звонок') {
			$("#call-panel").fadeIn();
		}
		return false;
	});
	$('#close_call').click(function(){
		$("#call-panel").fadeOut();
		return false;
	});
	$('#candel_c').click(function(){
		$("#call-panel").fadeOut();
		return false;
	});
	
	$("#send_phone").click(function(){

		var phone = $('#phone_call').val();
		var name = $('#name_call').val();
		
		$.post("/parfum/protect/back_phone.php",{
			phone: phone,
			name: name
		}, function(xml){
			$("message",xml).each(function(id){
				message = $("message",xml).get(id);

				$("#call-panel").hide();
				$( '#call_me' ).text("Скоро позвоним!").removeAttr("href");
				
			});
		});
	});
	
	$('[placeholder]').placeholder();
	$("#radio2").click(function() {
		if ($(this).val() == "on" || $(this).val() == "2") {
			$("#town-wrap").show();
		}
	});
	
	$("#radio1").click(function() {
		$("#town-wrap").hide();
	});
	
	$("#pass3").click(function() {
		if ($(this).val() == "on" || $(this).val() == "2") {
			$("#pass-wrap").show();
		}
	});
	
	$("#pass2").click(function() {
			$("#pass-wrap").hide();
	});
	
	$(".pass_radio").click(function() {
		if($(this).attr("id") == "zadat-pass") {
			$("#pass_enter").show();
		} else {
			$("#pass_enter").hide();
		}
	});
	
	
	$(".tabsWrap .header .tab").click(function() {
		var currElem = $(this);
		var currIndex = currElem.index();
		if (!currElem.hasClass("prices")) {
			$(".tabsWrap .header .tab").removeClass("active");
			currElem.addClass("active");
			$(".tabsWrap .body .block").hide();
			$(".tabsWrap .body .block:eq(" + currIndex + ")").show();
		}
	});
	
	
	$("#imgWrap .smallImgs .item").click(function() {
		var bigImg = $(this).attr("title");
		$("#imgWrap .bigImg img").attr("src",bigImg);
	});
	
	$("#imgWrap .smallImgs .right").click(function() {
		var countImgs = $("#imgWrap .smallImgs .inner .wide .item").length;
		var stopAnim = (87*countImgs - 87*2)*-1;
		var track = $("#imgWrap .smallImgs .inner .wide");
		var trackPosition = parseInt(track.css("margin-left"));
		if (trackPosition > stopAnim) {
			trackPosition = trackPosition - 87;
			track.animate({
				"margin-left": trackPosition + "px"
			});
		}
	});
	$("#imgWrap .smallImgs .left").click(function() {
		var countImgs = $("#imgWrap .smallImgs .inner .wide .item").length;
		var track = $("#imgWrap .smallImgs .inner .wide");
		var trackPosition = parseInt(track.css("margin-left"));
		trackPosition1 = trackPosition + 87;
		console.log(trackPosition);
		if (trackPosition < 0) {
			track.animate({
				"margin-left": trackPosition1 + "px"
			});
		}
	});
	
	$(".letterWrap a").click(function() {
		var currLetter = $(this).text();
		var oldLetter = $(".letterWrap").attr("data");
		
		if ((oldLetter == currLetter) || oldLetter == '') {
			$("#brandsPopup").toggle().toggleClass("hidden");
			$("#fade").toggle();
			$("#brandsPopup .letter").hide();
			$("#brandsPopup .letter."+currLetter).show();
		} else {
			if ($("#brandsPopup").hasClass("hidden")) {
				$("#brandsPopup").show().removeClass("hidden");
				$("#fade").show();
			}
			$("#brandsPopup .letter").hide();
			$("#brandsPopup .letter."+currLetter).show();
		}
		
		$(".letterWrap").attr("data",currLetter);
		
		return false
	});
	
	$("#fade").click(function() {
		$("#brandsPopup, #fade").hide();
		$("#brandsPopup").addClass("hidden");
	});
	
	
	
	
	
	
	
	
	
	
	
	
	
	
});
