var service = 0;
var master = 0;
var prc = 0;
$(document).ready(function () {
 $(".service:nth-child(4)").css("margin","0 0 0 2px");
  $(".foto_pr div:nth-child(6)").css("margin","0 0 0 4px");
  $(".category a:nth-child(3)").css("margin","0 0 0 0px");
  $(".category_shop a:nth-child(5)").css("margin","0 0 0 0px");
 $(".service").hover(
      function () {
        $(this).addClass("hover");
      },
      function () {
        $(this).removeClass("hover");
      }
    );

 $("ul.shop li, ul.shop-categories li, ul.albums li").hover(
      function () {
        $(this).addClass("hover");
      },
      function () {
        $(this).removeClass("hover");
      }
    );


 $('.head_menu ul li').hover(
        function() {
            $(this).addClass("active");
            $(this).find('ul').css("display","block");
        },
        function() {
            $(this).removeClass("active");
            $(this).find('ul').css("display","none");
        }
    );


   $('textarea.review').focus(function () 	{
										 	if ($(this).attr("value")=="Здесь можно оставить свой комментарий...")
         $(this).attr("value","");
    });

  $('textarea.kontakt').focus(function () {
										 	if ($(this).attr("value")=="Текст сообщения")

         $(this).attr("value","");
    });



    $('textarea.review').blur(function ()	{
	if ($(this).attr("value")=="")

         $(this).attr("value","Здесь можно оставить свой комментарий...");
    });



	    $('textarea.kontakt').blur(function () {

	if ($(this).attr("value")=="")

         $(this).attr("value","Текст сообщения");
    });


	$(".scr0 li a").click ( function () {
		salon = $(this).attr("rel");
		$("input[name=salon]").val(salon);
		$("input[name=salon_name]").val($(this).text());
		$(".scr0").hide();
		$(".scr1 li.sa_"+salon).show();
		$(".scr1").show();
		return false;
	});

	$(".scr1 li a").click ( function () {
		service = $(this).attr("rel");
		$("input[name=service]").val(service);
		$("input[name=service_name]").val($(this).text());
		$(".scr1").hide();
		$(".scr2 li.ch_"+service).show();
		$(".scr2").show();
		return false;
	});

	$(".scr2 li input").change ( function () {
		$("input[name=procedure_text]").val('');
		$(".scr2 li input").each ( function () {
			if ( $(this).attr("checked") )
				$("input[name=procedure_text]").val($("input[name=procedure_text]").val()+($("input[name=procedure_text]").val()?"; ":"")+$(this).parent().text());
		});
	});

	$(".scr2 a.next").click ( function () {		arr = $("input[name='procedure[]']:checked");
		cnt = $(arr).length;
		if ( $("input[name=procedure_text]").val() == '' ) {
			alert("Вы не выбрали ни одной процедуры!");
		}
		else {
			$(".scr2").hide();
			prc = 0;

			for (var i=0;i<cnt;i++) {				$(".scr3 li.ch_"+$(arr[i]).val()).show();
				$(".scr4 li.ch_"+$(arr[i]).val()).show();
				prc += $(".scr3 li.ch_"+$(arr[i]).val()).length;			}


			if ( prc )
				$(".scr3").show();
			else  {				//$(".scr4 li.ch_"+service).show();
				$(".scr4").show();
			}
		}
		return false;
	});

	$(".scr3 li input").change ( function () {
		$("input[name=subprocedure_text]").val('');
		$(".scr3 li input").each ( function () {
			if ( $(this).attr("checked") )
				$("input[name=subprocedure_text]").val($("input[name=subprocedure_text]").val()+($("input[name=subprocedure_text]").val()?"; ":"")+$(this).parent().text());
		});
	});

	$(".scr3 a.next").click ( function () {
		if ( $("input[name=subprocedure_text]").val() == '' ) {
			alert("Вы не выбрали ни одной подпроцедуры!");
		}
		else {
			$(".scr3").hide();
			//$(".scr4 li.ch_"+service).show();
			$(".scr4").show();
		}
		return false;
	});

	$(".scr4 li a").click ( function () {
		master = $(this).parent().attr("rel");
		$("input[name=master]").val(master);
		$("input[name=master_name]").val($(this).text());
		$(".scr4").hide();
		$(".scr5").show();
		return false;
	});

	$(".scr1 a.back").click ( function () {
		$(".scr1").hide();
		$(".scr1 li").hide();
		$(".scr0").show();
		return false;
	});

	$(".scr2 a.back").click ( function () {
		$(".scr2").hide();
		$(".scr2 input[type=checkbox]").removeAttr('checked');
		$(".scr2 li").hide();
		$(".scr1").show();
		return false;
	});

	$(".scr3 a.back").click ( function () {
		$(".scr3").hide();
		$(".scr3 input[type=checkbox]").removeAttr('checked');
		$(".scr3 li").hide();
		$(".scr2").show();
		return false;
	});

	$(".scr4 a.back").click ( function () {
		$(".scr4").hide();
		$(".scr4 li").hide();
		if ( prc == 0 )
			$(".scr2").show();
		else
			$(".scr3").show();
		return false;
	});

	$(".scr5 a.back").click ( function () {
		$(".scr5").hide();
		$(".scr5 li").hide();
		$(".scr4").show();
		return false;
	});

	$(".scr0").show();
	$(".scr0 li").show();
	$(".scr0 input[name=salon]").val('');
	$(".scr0 input[name=salon_name]").val('');
	$(".scr1 input[name=service]").val('');
	$(".scr1 input[name=service_name]").val('');
	$(".scr2 input[name=procedure_text]").val('');
	$(".scr2 input[type=checkbox]").removeAttr('checked');
	$(".scr3 input[name=subprocedure_text]").val('');
	$(".scr3 input[type=checkbox]").removeAttr('checked');
	$(".scr4 input[name=master]").val('');
	$(".scr4 input[name=master_name]").val('');
});
