﻿$(document).ready(function(){
calk ();
$("#calk-cont :text").change(function(){var pat = /['A-я','\s',',','.']/; if(pat.test($(this).attr("value"))) {$(this).attr("value", "0")};});
$("#calk-cont :checkbox").parent("label").mousedown(function(e){e.preventDefault()});
$("#calk-cont :text").focus(function(){$(this).attr("value","");calk()});
$("#calk-cont :input").change(function(){calk()});
$(".oth-list .oth-post:odd").css("background-color","#eee");
$(".oth-post, .tt").tooltip({track: true,delay: 500,fade: 250});
$(".oth-item .title").click(function(){$(this).toggleClass("down").next(".oth-list").slideToggle(750,'easeInOutBack')});

if($("#header").width() < 1600) {
$("#header .fl_right").css("background", "none")
$(".content").css("padding","0px 0px 0px 40px");
$(".content").css("width", "65%");
};
$(".menu-item:last div").css("border", "none");
$(".nt").removeAttr("title");
$(".sub-menu").prev(".menu-title").addClass("ml-list");
$(".ml-list").click(function () {$(this).toggleClass("ml-down").next(".sub-menu").slideToggle('normal')});
$(".mt-act").parent(".sub-menu").show().prev(".menu-title").addClass("ml-down");
$(".p-load").preloadify({ imagedelay:500,preload_parent: false });
$(".fastLink a").each(function() {$(this).addClass("scroll"); tg = "#entryID" + $(this).attr("href").substr(1);$(this).attr("href", tg );});

$(".scroll").click(function () {elementClick = $(this).attr("href");destination = $(elementClick).offset().top - 30;$("html").animate({ scrollTop: destination}, 1100 );return false;});

});

function calk () {var fin_cost = 0; var fin_day = 0; var day_str = "";
$("#calk-cont input:checked").each(function() {fin_cost += parseInt($(this).attr("cost"))});
$("#calk-cont input:checked").each(function() {fin_day += parseFloat($(this).attr("day"))});
var cp_page = parseInt($(".copy #page").attr("cost")) *  parseInt($(".copy #page").attr("value"));
var cp_page_d = parseFloat($(".copy #page").attr("day")) *  parseInt($(".copy #page").attr("value"));
var sh_post = parseInt($(".copy #shop-post").attr("cost")) *  parseInt($(".copy #shop-post").attr("value"));
var sh_post_d = parseFloat($(".copy #shop-post").attr("day")) *  parseInt($(".copy #shop-post").attr("value"));
if (isNaN(cp_page)) cp_page = 0; if (isNaN(cp_page_d)) cp_page_d = 0; 
if (isNaN(sh_post)) sh_post = 0; if (isNaN(sh_post_d)) sh_post_d = 0;
fin_cost += cp_page + sh_post;
fin_day = Math.ceil(fin_day + cp_page_d + sh_post_d);
if (fin_day == 1) {day_str = "день."}
else if ((1 < fin_day) && (fin_day < 5)) {day_str = "дня."}
else {day_str = "дней."};
$("#cost .value").text(fin_cost + " руб.");
$("#day .value").text(fin_day + " " + day_str);
};



