function howLong() {
		
			returnvalue = 0;
			allright = true;
			for (i=1; i<=8; i++) {
				if ($("#section" + i + "size").attr("value") < 40 || $("#section" + i + "size").attr("value") > 200) {allright = false;}
				if ($("#section" + i).css("display")=="block") {
					returnvalue += ($("#section" + i + "size").attr("value") - 0);
				}
			}
			if (allright) {
				$("#howlog_value").html(returnvalue);
			} else {
				alert ("Введите корректные данные в поля размеров секций");
				$("#howlog_value").html("???");
			}
		}
		function showSection(number) {
			tempi = 0;
			for (i=1;i<=8; i++) {
				if ($("#section" + i).css("display")=="block") {tempi++;}
			}
			if (tempi < number) {
				for (i=tempi; i<=number; i++) {$("#section" + i).fadeIn("slow");}
			} else {
				for (i=tempi; i>=number+1; i--) {$("#section" + i).fadeOut("slow");}
			}
			howLong();
		}
		function howMushIsTheFish() {
			// now, plug in baby!) © Muse
			if ($("#hiddendiv").css("display")=="block") {
					//вот здесь подсчёт
					$("#topResult").fadeOut("slow");
					//расчёты
					res = 0; res1 = 0; res2 = 0;
					sec = Math.round($("#slider0").slider("value")-0);
					height = (Math.round($("#slider1").slider("value")))/100;
					width = ($("#howlog_value").html()-0)/100;
					
					deep = (Math.round($("#slider2").slider("value")))/100;
					//alert(deep);
					res1 = width * deep * price_dsp * 2;
					res2 = (height * deep * price_dsp) + (sec * height * deep * price_dsp);
					
					res = res1 + res2;

					// а теперь проходим в цикле по всем видимым секциям, считаем всё для каждой и собираем вместе. индукция, блин)
					sectionsres = 0;
					for (i=1;i<=8; i++) {
						if ($("#section" + i).css("display")=="block") {
							//alert(i); // елси видима - значит считаем
							//ящики
							currentselect = 0;
							currentselect = $("#section" + i + "-optionbox").val()-0;
							if (($("#section" + i + "out-box").html()- 0)!=0) {
								switch(currentselect)
									{
									case 1:
										sectionsres += ($("#section" + i + "out-box").html()- 0) * price_box_type1;
									  break;    
									case 2:
										sectionsres += ($("#section" + i + "out-box").html()- 0) * price_box_type2;
									  break;
									case 3:
										sectionsres += ($("#section" + i + "out-box").html()- 0) * price_box_type3;
									  break;
									}
							}
							// полки
							if (($("#section" + i + "size").attr("value")-0)<=70) {
								sectionsres += ($("#section" + i + "out-shelf").html()- 0) * price_sec_small_shelf;
							} else {
								//alert(price_dsp);
								sectionsres = sectionsres + (price_dsp * (($("#section" + i + "out-shelf").html()- 0) * (($("#amount2").html()-0)/100) * ($("#section" + i + "size").attr("value")/100)));
								sectionsres -= 418;
							}
							//опции
							if ($("#section" + i + "-option1").attr("checked") == true) {
								if (($("#section" + i + "size").attr("value")-0)<=100) {
									sectionsres += price_sec_option1; // штанга
								} else {
									sectionsres += (($("#section" + i + "size").attr("value")-0)/100) * 290 * 73 * 4 *435; 
								}
								
							}
							if ($("#section" + i + "-option2").attr("checked")==true) {
								sectionsres += price_sec_option2; // торцевая
							}
							if ($("#section" + i + "-option3").attr("checked")==true) {
								sectionsres += price_sec_option3; // лифт
							}
						}
					}
					res += sectionsres;
					// опции всего шкафа - козырёк и цоколь
					if ($("#whatdoors1").attr("checked")==true) {
						//большие двери
						bigdoorsval = ($("#bigdoorsvalue").html()- 0);				
						for (i2=1; i2<=bigdoorsval; i2++) {
							res4=0;
							currentselect2 = 0;
							currentselect2 = $("#bigdoorstype" + i2).val()-0;
							//alert("#bigdoorstype" + i2);
								switch(currentselect2)
									{
									case 1:
										res4 = price_door_big1;
									  break;    
									case 2:
										res4 = price_door_big2;
									  break;
									case 3:
										res4 = price_door_big2;
										res4 += (($("#slider1").slider("value"))/100) * (width/bigdoorsval) * 5075;
									  break;
									case 4:
										res4 = price_door_big2;
										res4 += (($("#slider1").slider("value"))/100) * (width/bigdoorsval) * price_door_big4;
									  break;
									case 5:
										res4 = price_door_big2;
										res4 += (($("#slider1").slider("value"))/100) * (width/bigdoorsval) * price_door_big5;
									  break;
									case 6:
										res4 = price_door_big2;
										res4 += (($("#slider1").slider("value"))/100) * (width/bigdoorsval) * 2900;
									  break;
									case 7:
										res4 = price_door_big2;
										res4 += (($("#slider1").slider("value"))/100) * (width/bigdoorsval) * 2175;
									  break;
									case 8:
										res4 = price_door_big2;
										res4 += (($("#slider1").slider("value"))/100) * (width/bigdoorsval) * price_door_big8;
									  break;
									}
									res += res4; 
							}
						} else {
							smalldoorsval = ($("#smalldoorsvalue").html()- 0);
							for (i2=1; i2<=smalldoorsval; i2++) {
								res4=0;
								currentselect2 = 0;
								currentselect2 = $("#smalldoorstype"+ i2).val()-0;
								switch(currentselect2)
									{
									case 1:
										res4 = price_door_small1;
									  break;    
									case 2:
										res4 = price_door_small2;
									  break;
									case 3:
										res4 = price_door_small2;
										res4 += (($("#slider1").slider("value"))/100) * (width/smalldoorsval) * 5075;
									  break;
									case 4:
										res4 = price_door_small2;
										res4 += (($("#slider1").slider("value"))/100) * (width/smalldoorsval) * price_door_small4;
									  break;
									case 5:
										res4 = price_door_small2;
										res4 += (($("#slider1").slider("value"))/100) * (width/smalldoorsval) * price_door_small5;
									  break;
									case 6:
										res4 = price_door_small2;
										res4 += (($("#slider1").slider("value"))/100) * (width/smalldoorsval) *2900;
									  break;
									case 7:
										res4 = price_door_small2;
										res4 += (($("#slider1").slider("value"))/100) * (width/smalldoorsval) *2175;
									  break;
									case 8:
										res4 = price_door_small2;
										res4 += (($("#slider1").slider("value"))/100) * (width/smalldoorsval) * price_door_small8;
									  break;
									}
									//alert(res4);
									res += res4;
								}		
						}
				if($("#capcheck").attr("checked")==true) {
					res += ($("#capout").html()-0) * price_cap_without_lamp + price_cap_with_lamp;
				};
				
				//alert($("#shelfcheck").attr("checked"));
				if($("#shelfcheck").attr("checked") == true) {
					cursel = 0;
					cursel = $("#radshelftype").val()-0;
					res += 0;
					switch(cursel)
					{
						case 1:
							res += ($("#radshelfout").html()-0) * price_radshel_type1;
							break;
						case 2:
							res += ($("#radshelfout").html()-0) * price_radshel_type2;
							break;
					}
				};
				
				/*if($("#brushescheck").attr("checked")==true) {
					if ($("#whatdoors0").attr("checked")==true) {
						smalldoorsval = ($("#smalldoorsvalue").html()- 0);
						res = res + (price_brush * smalldoorsval * (height * 2));
					} else {
						bigdoorsval = ($("#bigdoorsvalue").html()- 0);
						res = res + (price_brush * bigdoorsval * (height * 2));
					}
				};*/
				
				if($("#zokolcheck").attr("checked")==true) {
					res = res + price_zokol;
				};

				torzsel = 0;
				torzsel = $("#radshelftype2").val()-0;
					switch(torzsel)
					{
						case 1:
							res += 0;
							break;
						case 2:
							res += (($("#howlog_value").html()-0)/100) * (($("#amount1").html()-0)/100) * price_torz_pvh;
							break;
						case 3:
							res += (($("#howlog_value").html()-0)/100) * (($("#amount1").html()-0)/100) * price_torz_alum;
							break;
					}
				//вывод окошка с ценой, перед выводом округлем цену.
				$("#topResult").fadeIn("slow");
				$("#result").html(Math.round(res) + " руб.");
				$("#sendres").fadeIn("slow");
				//doors
				$.post("stat.php", { name: "John", time: "2pm" },
		   function(data){
		     //alert("Data Loaded: " + data);
		   });
			} else {
				// а вот тут вывод дверей перед подсчётом
				$("#calc").fadeOut("fast");
				// тут считаем количество дверей.
				smallvalue = 0; bigvalue = 0; //обьявили значения
				
				smallvalue = Math.floor($("#howlog_value").html() / 90) + 1; // Math.floor - берёт целую часть от числа
				bigvalue = Math.floor($("#howlog_value").html() / 105) + 1;
				
				if (smallvalue == 1) {
					smallvalue=2;
				};
				if (bigvalue == 1) {
					bigvalue=2;
				};
				
				for (i=2; i<=smallvalue; i++) {
					send = i + '-ая дверь&nbsp;&nbsp;<select id="smalldoorstype' + i + '" size="1"><option value="1" selected>Дсп</option><option value="2">Зеркало</option><option value="8">Зеркало бронза</option><option value="4">Тонированное стекло</option><option value="5">Матовое стекло</option></select><br>';
					$("#smalldoorstypeout").html($("#smalldoorstypeout").html() + send);
				}
				
				for (i=2; i<=bigvalue; i++) {
					send = i + '-ая дверь&nbsp;&nbsp;<select id="bigdoorstype' + i + '" size="1"><option value="1" selected>Дсп</option><option value="2">Зеркало</option><option value="8">Зеркало бронза</option><option value="4">Тонированное стекло</option><option value="5">Матовое стекло</option></select><br>';
					$("#bigdoorstypeout").html($("#bigdoorstypeout").html() + send);
				}
				
				if (smallvalue == bigvalue) {
					//bigvalue = 0;
					$("#whatdoors1").attr("disabled","disabled");
					$("#bigdoorstype1").attr("disabled","disabled");
					$("#whatdoors0").attr("checked","checked");
					for (i=2; i<=bigvalue; i++) {
						$("#bigdoorstype"+i).attr("disabled","disabled");
					}
				}

				$("#smalldoorsvalue").html(smallvalue);
				$("#bigdoorsvalue").html(bigvalue);
				$("#buttontitle").html("Рассчитать стоимость")
				$("#hiddendiv").fadeIn("slow");
			}
		}
		//sending result via ajax
		function sendresult() {
			if ($("#sendform").css("display")=="block") {
				//sending here
				if (($("#firstname").val() == "") || ($("#lastname").val() == "") || ($("#phone").val() == "") || ($("#email").val() == "")) {
					alert("Поля: Телефон, Имя, Фамилия, email — обязательны для заполнения.");
				} else {
					var sectionsWidthArray = new Array();
					var sectionsBoxArray = new Array();
					var sectionsBoxTypeArray = new Array();
					var sectionsShelfArray = new Array();
					var sectionsVewalo1Array = new Array();
					var sectionsVewalo2Array = new Array();
					var sectionsVewalo3Array = new Array();
					var issmalldoors = false;
					var smallDoorsArray = new Array();
					var bigDoorsArray  = new Array();
					var havezokol = false;
					var haveradshelf = false;
					var radshelfnumber = 0;
					var havelight = false;
					var lightnumber = 0;
					var shelfcant = 0;
					var boxcant = 0;
					for (i=1;i<=8; i++) {
						if ($("#section" + i).css("display")=="block")
						{
							sectionsWidthArray.push($("#section" + i + "size").attr("value"));
							sectionsBoxArray.push($("#section" + i + "slider-box").slider("value"));
							sectionsBoxTypeArray.push($("#section" + i + "-optionbox").attr("value"));
							sectionsShelfArray.push($("#section" + i + "slider-shelf").slider("value"));
							if ($("#section" + i + "-option1").attr("checked")==true) {
								sectionsVewalo1Array.push("1");
							} else {
								sectionsVewalo1Array.push("0");
							}
							if ($("#section" + i + "-option2").attr("checked")==true) {
								sectionsVewalo2Array.push("1");
							} else {
								sectionsVewalo2Array.push("0");
							}
							if ($("#section" + i + "-option3").attr("checked")==true) {
								sectionsVewalo3Array.push("1");
							} else {
								sectionsVewalo3Array.push("0");
							}
							if ($("#whatdoors0").attr("checked")==true) {
								issmalldoors = true;
							} else {issmalldoors = false;}
						}
					}
					smalldoorsval = ($("#smalldoorsvalue").html()- 0);
					for (i=1;i<=smalldoorsval; i++) {
						smallDoorsArray.push($("#smalldoorstype" + i).attr("value"));
					}
					bigdoorsval = ($("#bigdoorsvalue").html()- 0);
					for (i=1;i<=bigdoorsval; i++) {
						bigDoorsArray.push($("#bigdoorstype" + i).attr("value"));
					}
					
					if ($("#zokolcheck").attr("checked")==true) {
						havezokol = 1;
					} else {
						havezokol = 0;
					}
					
					if ($("#shelfcheck").attr("checked")==true) {
						haveradshelf = 1;
						radshelfnumber = $("#radshelfslider").slider("value")-0;
					} else {
						haveradshelf = 0;
						radshelfnumber = 0;
					}
					
					if ($("#capcheck").attr("checked")==true) {
						havelight = 1;
						lightnumber = $("#capslider").slider("value")-0;
					} else {
						havelight = 0;
						lightnumber = 0;
					}
					
					shelfcant = $("#radshelftype").attr("value");
					boxcant = $("#radshelftype2").attr("value");
					
					$.post("send.php", 
						{
							//список параметров.
							firstname: $("#firstname").val(),
							lastname: $("#lastname").val(),
							email: $("#email").val(),
							phone: $("#phone").val(),
							adress: $("#adress").val(),
							comment: $("#comment").val(),
							
							height: (Math.round($("#slider1").slider("value")))/100,
							deep: (Math.round($("#slider2").slider("value")))/100,
							width: ($("#howlog_value").html()-0)/100,
							sections: Math.round($("#slider0").slider("value")-0),
							'sectionsWidth[]': sectionsWidthArray,
							'sectionsBox[]': sectionsBoxArray,
							'sectionsBoxType[]': sectionsBoxTypeArray,
							'sectionsShelf[]': sectionsShelfArray,
							'sectionsVewalo1[]': sectionsVewalo1Array,
							'sectionsVewalo2[]': sectionsVewalo2Array,
							'sectionsVewalo3[]': sectionsVewalo3Array,
							isitsmalldoors: issmalldoors,
							smalldoorscount : smalldoorsval,
							bigdoorscount : bigdoorsval,
							'smalldoors[]': smallDoorsArray,
							'bigdoors[]': bigDoorsArray,
							havezokol : havezokol,
							haveradshelf : haveradshelf,
						    radshelfnumber : radshelfnumber,
						    havelight: havelight,
						    lightnumber: lightnumber,
						    shelfcant: shelfcant,
						    boxcant: boxcant
						},
				    function(datares){
				    	if(datares == "0") {
				    		alert("Ваш заказ принят в обработку.");
				    	} else {
				    		alert("Ошибка отправки - неполадки на сервере, или отсутствует подключение к интернету, попробуйте позже.");
				    		//alert(datares);
				    	}
				    });
				}
			} else {
				$("#topResult").fadeOut("slow");
				$("#hiddendiv").fadeOut("slow");
				$("#resultbutton1").fadeOut("slow");
				
				$("#sendres").fadeIn("slow");
				$("#sendform").fadeIn("slow");
				
				$("#buttontitle22").html("Отправить заказ");
			}
		}

			$(function(){
				// слайдер для количества секций
				$("#slider0").slider({
					value: 3, min: 1, max: 8, step: 1,
					slide: function(e, uitop) {
						//------------------------------------------------------------------------
						$("#amount0").html(Math.round(uitop.value));
						showSection(uitop.value);
						howLong();
					}
				});
				//высота
				$("#slider1").slider({
					value: 200, min: 147, max: 280, step: 1,
					slide: function(event, ui) {$("#amount1").html(Math.round(ui.value));}
				});
				//глубина
				$("#slider2").slider({
					value: 60, min: 20, max: 100, step: 1,
					slide: function(event, ui) {$("#amount2").html(Math.round(ui.value));}
				});
				$("#radshelfslider").slider({
					value: 0, min: 0, max: 10, step: 1,
					slide: function(event, ui) {
						$("#radshelfout").html(Math.round(ui.value));
						if(Math.round(ui.value)!=0) {$("#shelfcheck").attr("checked","checked");};
					}
				});
				$("#capslider").slider({
					value: 0, min: 0, max: 10, step: 1,
					slide: function(event, ui) {
						$("#capout").html(Math.round(ui.value));
						if(Math.round(ui.value)!=0) {$("#capcheck").attr("checked","checked");};
					}
				});
				// инициализация слайдеров для секций :-! и это только ящик, мать вашу. ибо js не поддерживает эту хрень в цикле. чтоб они в аду горели со своими callback'ами
					$("#section1slider-box").slider({value: 0, min: 0, max: 7, step: 1, orientation: "horizontal",slide: function(event, uifor) {$("#section1out-box").html(Math.round(uifor.value));}});
					$("#section2slider-box").slider({value: 0, min: 0, max: 7, step: 1, orientation: "horizontal",slide: function(event, uifor) {$("#section2out-box").html(Math.round(uifor.value));}});
					$("#section3slider-box").slider({value: 0, min: 0, max: 7, step: 1, orientation: "horizontal",slide: function(event, uifor) {$("#section3out-box").html(Math.round(uifor.value));}});
					$("#section4slider-box").slider({value: 0, min: 0, max: 7, step: 1, orientation: "horizontal",slide: function(event, uifor) {$("#section4out-box").html(Math.round(uifor.value));}});
					$("#section5slider-box").slider({value: 0, min: 0, max: 7, step: 1, orientation: "horizontal",slide: function(event, uifor) {$("#section5out-box").html(Math.round(uifor.value));}});
					$("#section6slider-box").slider({value: 0, min: 0, max: 7, step: 1, orientation: "horizontal",slide: function(event, uifor) {$("#section6out-box").html(Math.round(uifor.value));}});
					$("#section7slider-box").slider({value: 0, min: 0, max: 7, step: 1, orientation: "horizontal",slide: function(event, uifor) {$("#section7out-box").html(Math.round(uifor.value));}});
					$("#section8slider-box").slider({value: 0, min: 0, max: 7, step: 1, orientation: "horizontal",slide: function(event, uifor) {$("#section8out-box").html(Math.round(uifor.value));}});
				// инициализация слайдеров для секций :-! полки
					$("#section1slider-shelf").slider({value: 0, min: 0, max: 7, step: 1, orientation: "horizontal",slide: function(event, uifor) {$("#section1out-shelf").html(Math.round(uifor.value));}});
					$("#section2slider-shelf").slider({value: 0, min: 0, max: 7, step: 1, orientation: "horizontal",slide: function(event, uifor) {$("#section2out-shelf").html(Math.round(uifor.value));}});
					$("#section3slider-shelf").slider({value: 0, min: 0, max: 7, step: 1, orientation: "horizontal",slide: function(event, uifor) {$("#section3out-shelf").html(Math.round(uifor.value));}});
					$("#section4slider-shelf").slider({value: 0, min: 0, max: 7, step: 1, orientation: "horizontal",slide: function(event, uifor) {$("#section4out-shelf").html(Math.round(uifor.value));}});
					$("#section5slider-shelf").slider({value: 0, min: 0, max: 7, step: 1, orientation: "horizontal",slide: function(event, uifor) {$("#section5out-shelf").html(Math.round(uifor.value));}});
					$("#section6slider-shelf").slider({value: 0, min: 0, max: 7, step: 1, orientation: "horizontal",slide: function(event, uifor) {$("#section6out-shelf").html(Math.round(uifor.value));}});
					$("#section7slider-shelf").slider({value: 0, min: 0, max: 7, step: 1, orientation: "horizontal",slide: function(event, uifor) {$("#section7out-shelf").html(Math.round(uifor.value));}});
					$("#section8slider-shelf").slider({value: 0, min: 0, max: 7, step: 1, orientation: "horizontal",slide: function(event, uifor) {$("#section8out-shelf").html(Math.round(uifor.value));}});
				// но и это ещё не всё!) тут надо установить дефолтные ноли, но мне впадлу этим заниматься,because я забил их жёстко в код.. ;)
					
				$("#amount0").html($("#slider0").slider("value"));
				$("#amount1").html($("#slider1").slider("value"));
				$("#amount2").html($("#slider2").slider("value"));
				$("#capout").html($("#capslider").slider("value"));
				$("#radshelfout").html($("#radshelfslider").slider("value"));
				
				showSection("3");
				howLong();
				
			    $("#slider0").hover(
			      function () {
			        howLong();
			      }, 
			      function () {
			        howLong();
			      }
			    );
			    $("#slider0").mouseover(function(){
			      howLong();
			    }).mouseout(function(){
			      howLong();
			    });
			});