$("document").ready(
function(){  $("#left").hide();
   $("document").pngFix();
    $.fn.fancyzoom.defaultsOptions.imgDir='resources/image/fancyzoom/';
   	 $.fn.fancyzoom.defaultsOptions.showoverlay='true';
    $("a#construct_button").click(function(){    	 window.open("construct");
    	});
    $("a.tozoom").fancyzoom();
    $("#main_result").find(".container-hot").find(".container-hot-pict").find("a").click(function(){
    	 $.get('resources/scripts/id_door.php?num='+$(this).attr("rel")+'&page=1', AppendCheckAll);
    	});
    $("#main_result").find(".container-hotnews").find(".container-news").find("a").click(function(){

    	 $.get('resources/scripts/news.php?num='+$(this).attr("rel"), AppendCheckAll);
    	});
     $("#popup2").hide();
    $("#popup").click(function()
    {
       $("#popup2").show("200");   
      
    });
	
	$("#right").click(function ()
		{
			$("#scrollable").animate({
				right: "+=420px"
				}, "slow");
				$("#right").hide('slow');
				$("#left").show('slow');
		})
		$("#left").click(function ()
		{
			$("#scrollable").animate({
				right:	"-=420px"
				}, "slow");
				$("#right").show('slow');
				$("#left").hide('slow');
		})
	
   /*-----------------------------------doors.php-------------------------------*/
   /*--------doors-type*/
   $("a#check_1").click(function(){   $.get('resources/scripts/doors.php?type='+$(this).attr("rel"), AppendCheck);
   });
   $("a#check_2").click(function(){
   $.get('resources/scripts/doors.php?type='+$(this).attr("rel"), AppendCheck);
    });
   $("a#check_all").click(function(){
   $.get('resources/scripts/doors.php', AppendCheckAll);
   });

   function AppendCheck(data)
   {
      $("div#result_type")
      .empty()
      .append(data);
				$("div#result_type").find("a").click(function(){
				if ($(this).attr("id") == "into_bag"){
				$.get('resources/scripts/bag.php?door='+ $(this).attr("rel") +'&action=add', AppendCheckIDDoor);
				}
				else {
				$.get('resources/scripts/id_door.php?num='+$(this).attr("rel"), AppendCheckIDDoor);
				}
				});
   };
   function AppendCheckAll(data)
   {
      $("div#main_result")
      .empty()
      .append(data);
       $("a.tozoom").fancyzoom();
				$("div#result_type").find("a").click(function(){
				if ($(this).attr("id") == "into_bag"){
				$.get('resources/scripts/bag.php?door='+ $(this).attr("rel") +'&action=add', AppendCheckIDDoor);
				}
				else {
				$.get('resources/scripts/id_door.php?num='+$(this).attr("rel"), AppendCheckIDDoor);
				}
				});
   };
   /*--------doors-type-end*/

   $("div#result_type").find("a").click(function(){   	if ($(this).attr("id") == "into_bag"){   		 $.get('resources/scripts/bag.php?door='+ $(this).attr("rel") +'&action=add', AppendCheckIDDoor);
   	}
   else {
   $.get('resources/scripts/id_door.php?num='+$(this).attr("rel"), AppendCheckIDDoor);
   }
   });
   function AppendCheckIDDoor(data)
   {
      $("div#main_result")
      .empty()
      .append(data);
      $("a.tozoom").fancyzoom();
           /*---------------------------------------id-door--------------------------------*/
              $("#main_result").find(".container-config-menu").find("a#prev").click(function(){              	 //alert("javascript:sendRequest(\'resources/scripts/id_door.php?num='.$_id_down.'\', \'main_result\', \'GET\'");
              	 $.get('resources/scripts/id_door.php?num='+$(this).attr('rel'), AppendCheckIDDoor);
              	});
              $("#main_result").find(".container-config-menu").find("a#next").click(function(){
              	 //alert("javascript:sendRequest(\'resources/scripts/id_door.php?num='.$_id_up.'\', \'main_result\', \'GET\'");
              	 $.get('resources/scripts/id_door.php?num='+$(this).attr('rel'), AppendCheckIDDoor);
              	});

           /*------------------------------------end---id-door--------------------------------*/
            $("#main_result").find(".container-menu-bag").find("a#make_order").click(function(){
           $.get('resources/scripts/bag.php?action=make', bagShowMainresult)

     	});
     		 $("#main_result").find(".bag-line").find("a").click(function(){
           $.get('resources/scripts/bag.php?door='+$(this).attr("rel")+'&action=delete', bagShowMainresult)

     	});


   };

   /*---------------------------------end--doors.php-------------------------------*/

   /*-----------------------------------furnitura.php-------------------------------*/

    $("div#main_result").find("div.furnitura-menu").find("a").click(function(){      $.get('resources/scripts/furnitura_module.php?procces=2&id='+$(this).attr("rel"), checkFurnitura);
   	});
     	function checkFurnitura(data)
     	{     		$("div#main_result")
     				.empty()
     				.append(data);
     		$("div#main_result").find("a.tozoom").fancyzoom();
     	 $("div#main_result").find("div.furnitura-menu").find("a").click(function(){
       		$.get('resources/scripts/furnitura_module.php?procces=2&id='+$(this).attr("rel"), checkFurnitura);
   			});
     	};


	/*---------------------------------end-furnitura.php-------------------------------*/
    /*-----------------------------------about.php-------------------------------*/
       $("div#main_result").find("a#sotrudniki").click(function(){
         $.get('resources/files/our_worker.txt', ShowData);
     	});
     $("div#main_result").find("a#history").click(function(){         $.get('resources/about.html', ShowData);
     	});
     $("div#main_result").find("a#prioritets").click(function(){
         $.get('resources/prioritets.html', ShowData);
     	});
     $("div#main_result").find("a#clients").click(function(){
         $.get('resources/scripts/our_clients.php', ShowData);
     	});
     function ShowData(data)
     {     	$("div#main_result").find("div#result")
     			.empty()
     	        .append(data);
     	         $("a.tozoom").fancyzoom();
     }
    /*-----------------------------------end-about.php-------------------------------*/
    /*-----------------------------------akciya.php-------------------------------*/
      $("div#main_result").find("a#akc_reg").click(function(){      	 if (!$("div#main_result").find("#name").attr("value"))
      	 				{
                     	alert('Не все обязательные поля заполнены. Заполните их пожалуйста.');
                     	}
                     	else{
                    	 	var params = '&name=' + encodeURIComponent($("div#main_result").find("#name").attr("value")) + '&tel=' + encodeURIComponent($("div#main_result").find("#tel").attr("value")) + '&mail=' + encodeURIComponent($("div#main_result").find("#mail").attr("value"));
                     		$.get('resources/scripts/akciya.php?action=2' + params, AkciyaReg);
                     		}
       	});
       	function AkciyaReg(data)
       	{       		$("div#main_result")
     			.empty()
     	        .append(data);
       	}


	/*-----------------------------------end-akciya.php-------------------------------*/
    /*-----------------------------------inter_info.php-------------------------------*/
       $("div#main_result").find("a#story").click(function(){
        $.get('resources/scripts/inter_info.php?id=1', showStory)

       });
       $("div#main_result").find("a#tech").click(function(){
       $.get('resources/scripts/inter_info.php?id=2', showTech)

       });
       $("div#main_result").find("a#foto").click(function(){
       $.get('resources/scripts/inter_info.php?id=3', showFoto)

       });
       $("div#main_result").find("div#result_out").find("a").click(function(){
       	 	  $.get($(this).attr("rel"), showOneStory);

       	 	});
       	 	function showOneStory(data)
       	 	{
       	 		$("div#main_result").find("div#result_out")
       	 			.empty()
       	 			.append("<div id=\"info_res_story\">"+data+"</div>");
       	 			$("a.tozoom").fancyzoom();
       	 	}


       function showStory(data)
       {       	 $("div#main_result").find("div#result_out")
       	 	.empty()
       	 	.append(data);
       	 $("div#main_result").find("div#result_out").find("a").click(function(){       	 	  $.get($(this).attr("rel"), showOneStory);

       	 	});
       	 	function showOneStory(data)
       	 	{       	 		$("div#main_result").find("div#result_out")
       	 			.empty()
       	 			.append("<div id=\"info_res_story\">"+data+"</div>");
       	 	}
       }

       function showTech(data)
       {
       	 $("div#main_result").find("div#result_out")
       	 	.empty()
       	 	.append(data);
       	  $("div#main_result").find("div#result_out").find("a").click(function(){
       	  	$.get('resources/scripts/tech_id.php?leter='+$(this).attr("rel"), showTerms)
       	  	})

       	  	function showTerms(data)
       	  	{             	$("div#main_result").find("div#result_out").find("div#info_res_id")
             			.empty()
             			.append(data);
       	  	}
       }

       function showFoto(data)
       {
       	 $("div#main_result").find("div#result_out")
       	 	.empty()
       	 	.append(data);
       }
    /*-----------------------------------end-inter_info.php-------------------------------*/
    /*-----------------------------------bag.php-------------------------------------*/
     $("#main_result").find(".container-menu-bag").find("a#make_order").click(function(){           $.get('resources/scripts/bag.php?action=make', bagShowMainresult)

     	});
     	 $("#main_result").find(".bag-line").find("a").click(function(){
           $.get('resources/scripts/bag.php?door='+$(this).attr("rel")+'&action=delete', bagShowMainresult)

     	});


       function bagShowMainresult(data)
       {       	 $("#main_result")
       	 	.empty()
       	 	.append(data);
       	 $("#main_result").find(".container-menu-bag").find("a#make_order").click(function(){
           $.get('resources/scripts/bag.php?action=make', bagShowMainresult)

     	});
     	 $("#main_result").find(".bag-line").find("a").click(function(){
           $.get('resources/scripts/bag.php?door='+$(this).attr("rel")+'&action=delete', bagShowMainresult)

     	});
       	 $("#main_result").find("a#cancle").click(function(){       	 	 $.get('resources/scripts/bag.php?action=show', bagShowMainresult);
       	 	})
       	 $("#main_result").find("a#done").click(function(){       	 	 res = validateOrder();
			 if (res == true){
       	 	 params = '&name=' + encodeURIComponent($("#main_result").find('#name').attr("value")) + '&sec_name=' + encodeURIComponent($("#main_result").find('#sec_name').attr("value")) + '&fath_name=' + encodeURIComponent($("#main_result").find('#fath_name').attr("value")) + '&tel_mob=' + encodeURIComponent($("#main_result").find('#tel_mob').attr("value")) + '&tel_dom=' + encodeURIComponent($("#main_result").find('#tel_dom').attr("value")) + '&e_mail=' + encodeURIComponent($("#main_result").find('#e_mail').attr("value"));
       	 	 $.get('resources/scripts/bag.php?action=finish'+params, bagShowMainresult);
       	 	 }
       	 	})
       }


   /*-----------------------------------end-bag.php-------------------------------*/
	/*---------------------------------price.php-----------------------------------*/
	$(".optional").change(function()
	{	//alert("WORK");
		var elemant =$(this).find(".opt").attr("selected")
		var page = $(this).find(".opt:selected").attr("rel");
		//alert(page);
		if (page) {
			$.get(page, function(data){
				$("#info-part").hide().empty().append(data).show(200);
				
			});
		}
		
	})
	
	/*-------------------------------------end-price.php---------------------------*/



	/*конец он реади */ });
	function validateOrder()
{
	var res = false;
    if (!document.getElementById('name').value){
    	    	alert('Вы не ввели имя. Это поле обязательно для заполнения');
    	    	res = false;
    }  else { res = true}
    if (!document.getElementById('sec_name').value){
    	    	alert('Вы не ввели фамилию. Это поле обязательно для заполнения');
    	    	res = false;
    } else  { res = true}
    if (!document.getElementById('fath_name').value){
    	    	alert('Вы не ввели отчество. Это поле обязательно для заполнения');
    	    	res = false;
    } else {res = true}
    if (!document.getElementById('tel_mob').value){
    	    	alert('Вы не ввели контактный телефон. Это поле обязательно для заполнения');
	            res = false
	} else {res = true}
	return res;
}

    function closePopup()
    {
      $("#popup2").hide();
    };
       function gotoDoors()
    {
      location.href = "galery.php";
      $("#popup2").hide();
    };
