function add_iframe(elm) {
    if ($.browser.msie && $.browser.version <= 6 && $(".pre_ie_iframe", elm).length == 0) {
        var elm_w = elm.width();
        var elm_h = elm.height();
        var elm_z = (elm.css("z-index") != 0) ? elm.css("z-index") - 1 : 0;
        elm.wrapInner('<div class="pre_ie_iframe"></div>');
        $(".pre_ie_iframe", elm).css({
            height: elm_h,
            left: 0,
            position: "absolute",
            top: 0,
            width: elm_w,
            zIndex: elm_z + 1
        });
        $("<iframe></iframe>").attr({
            className: "ie_iframe"
        }).css({
            border: 0,
            height: elm_h,
            left: 0,
            opacity: 0,
            position: "absolute",
            top: 0,
            width: elm_w,
            zIndex: elm_z
        }).appendTo(elm);
        $(elm).bind("resize", function () {
            var elm_w = elm.width();
            var elm_h = elm.height();
            $(".pre_ie_iframe", elm).css({
                height: elm_h,
                width: elm_w
            });
            $(".ie_iframe", elm).css({
                height: elm_h,
                width: elm_w
            })
        })
    }
    return
}
function cast_blanket(popup, time, o_args) {
    var document_h = $(document).height();
    var document_w = $(document).width();
    var opacity = .5;
    if (o_args.opacity) {
        opacity = o_args.opacity
    }
    $("<div></div>").attr({
        id: "blanket"
    }).css({
        height: document_h,
        left: 0,
        opacity: opacity,
        position: "absolute",
        top: 0,
        width: document_w,
        zIndex: 100
    }).appendTo($("body"));
    if ($.browser.msie) {
        $("<iframe></iframe>").attr({
            id: "blanket_iframe"
        }).css({
            border: 0,
            height: document_h,
            left: 0,
            opacity: 0,
            position: "absolute",
            top: 0,
            width: document_w,
            zIndex: 99
        }).appendTo($("body"))
    }
    if (o_args.type == "img" && typeof (o_args.list) == 'object' && o_args.indx !== '') {
        popup.width(o_args.list[o_args.indx]["width"] + 20);
        $(".img a", popup).empty();
        $(".title", popup).empty();
        $("<img />").attr({
            //height: o_args.list[o_args.indx]["height"],
            src: o_args.list[o_args.indx]["photo"],
            width: o_args.list[o_args.indx]["width"]
        }).appendTo($(".img a", popup));
        $("<p />").text(o_args.list[o_args.indx]["title"]).appendTo($(".title", popup));
        $(".count .curr", popup).text(o_args.indx + 1);
        $(".count .total", popup).text(o_args.total);
        if (o_args.indx < o_args.total - 1) {
            $(".nav_next a", popup).unbind("click");
            $(".img a", popup).unbind("click");
            $(".nav_next a", popup).bind("click", function (e) {
                e.preventDefault();
                var args = new Object();
                args = {
                    "list": o_args.list,
                    "indx": o_args.indx + 1,
                    "total": o_args.total
                };
                change_photo(popup, args)
            });
            $(".img a", popup).bind("click", function (e) {
                e.preventDefault();
                var args = new Object();
                args = {
                    "list": o_args.list,
                    "indx": o_args.indx + 1,
                    "total": o_args.total
                };
                change_photo(popup, args)
            });
            $(".nav_next", popup).css({
                visibility: "visible"
            }).show(10, function () {
                $(".nav_next img", popup).ifixpng()
            })
        } else {
            $(".nav_next a", popup).unbind("click");
            $(".nav_next a", popup).bind("click", function (e) {
                e.preventDefault()
            });
            $(".img a", popup).unbind("click");
            $(".img a", popup).bind("click", function (e) {
                e.preventDefault();
                remove_blanket(popup, 0)
            });
            $(".nav_next", popup).css({
                visibility: "hidden"
            }).hide()
        } if (o_args.indx > 0) {
            $(".nav_prev a", popup).unbind("click");
            $(".nav_prev a", popup).bind("click", function (e) {
                e.preventDefault();
                var args = new Object();
                args = {
                    "list": o_args.list,
                    "indx": o_args.indx - 1,
                    "total": o_args.total
                };
                change_photo(popup, args)
            });
            $(".nav_prev", popup).css({
                visibility: "visible"
            }).show(10, function () {
                $(".nav_prev img", popup).ifixpng()
            })
        } else {
            $(".nav_prev a", popup).unbind("click");
            $(".nav_prev a", popup).bind("click", function (e) {
                e.preventDefault()
            });
            $(".nav_prev", popup).css({
                visibility: "hidden"
            }).hide()
        }
    }
    position_popup(popup);
    if (time != 0) {
        popup.fadeIn(time, change_blanket)
    } else {
        popup.show(10, change_blanket)
    }
    $(window).bind("resize", function () {
        change_blanket();
        position_popup(popup)
    });
    $("#blanket").bind("click", function () {
        $(window).unbind("resize");
        remove_blanket(popup, 0)
    });
    return
}
function change_blanket() {
    var document_h = $(document).height();
    var document_w = $(document).width();
    if ($.browser.msie && $.browser.version <= 6 && ($(window).height() - $(document).height() < 0)) {
        document_w -= 17
    }
    $("#blanket").css({
        height: document_h,
        width: document_w
    });
    $("#blanket_iframe").css({
        height: document_h,
        width: document_w
    })
}
function change_photo(popup, o_args) {
    var view_height = $(window).height();
    var view_width = $(window).width();
    var time = 300;
    if (typeof (o_args.list) == 'object' && o_args.indx !== '') {
        popup.fadeOut(time, function () {
            popup.css({
                width: o_args.list[o_args.indx]["width"] + 20
            });
            $(".img a", popup).empty();
            $(".title", popup).empty();
            $("<img />").attr({
             //   height: o_args.list[o_args.indx]["height"],
                src: o_args.list[o_args.indx]["photo"],
                width: o_args.list[o_args.indx]["width"]
            }).appendTo($(".img a", popup));
            $("<p />").text(o_args.list[o_args.indx]["title"]).appendTo($(".title", popup));
            $(".count .curr", popup).text(o_args.indx + 1);
            $(".count .total", popup).text(o_args.total);
            if (o_args.indx < o_args.total - 1) {
                $(".nav_next a", popup).unbind("click");
                $(".img a", popup).unbind("click");
                $(".nav_next a", popup).bind("click", function (e) {
                    e.preventDefault();
                    var args = new Object();
                    args = {
                        "list": o_args.list,
                        "indx": o_args.indx + 1,
                        "total": o_args.total
                    };
                    change_photo(popup, args)
                });
                $(".img a", popup).bind("click", function (e) {
                    e.preventDefault();
                    var args = new Object();
                    args = {
                        "list": o_args.list,
                        "indx": o_args.indx + 1,
                        "total": o_args.total
                    };
                    change_photo(popup, args)
                });
                $(".nav_next", popup).css({
                    visibility: "visible"
                }).show();
                if ($.browser.msie && $.browser.version <= 6) {
                    setTimeout(function () {
                        $(".nav_next img", popup).ifixpng()
                    }, time)
                }
            } else {
                $(".nav_next a", popup).unbind("click");
                $(".nav_next a", popup).bind("click", function (e) {
                    e.preventDefault()
                });
                $(".img a", popup).unbind("click");
                $(".img a", popup).bind("click", function (e) {
                    e.preventDefault();
                    remove_blanket(popup, 0)
                });
                $(".nav_next", popup).css({
                    visibility: "hidden"
                }).hide()
            } if (o_args.indx > 0) {
                $(".nav_prev a", popup).unbind("click");
                $(".nav_prev a", popup).bind("click", function (e) {
                    e.preventDefault();
                    var args = new Object();
                    args = {
                        "list": o_args.list,
                        "indx": o_args.indx - 1,
                        "total": o_args.total
                    };
                    change_photo(popup, args)
                });
                $(".nav_prev", popup).css({
                    visibility: "visible"
                }).show();
                if ($.browser.msie && $.browser.version <= 6) {
                    setTimeout(function () {
                        $(".nav_prev img", popup).ifixpng()
                    }, time)
                }
            } else {
                $(".nav_prev a", popup).unbind("click");
                $(".nav_prev a", popup).bind("click", function (e) {
                    e.preventDefault()
                });
                $(".nav_prev", popup).css({
                    visibility: "hidden"
                }).hide()
            }
            position_popup(popup);
            popup.fadeIn(400, change_blanket)
        })
    }
    return
}
function check_str_lngth(elm, max, parent) {
    var elm_val = elm.val();
    if (elm_val.length > max) {
        var elm_val_new = elm_val.substring(0, max);
        elm.val(elm_val_new);
        $(".counter", elm.parents(parent)).text("0")
    } else {
        $(".counter", elm.parents(parent)).text(max - elm_val.length)
    }
    return
}
function correct_a_tab() {
    if ($.browser.msie && $.browser.version <= 6) {
        $("#m_top_1 .a .t").width($("#m_top_1 .a").width())
    }
    return
}
function correct_footer_pos() {
    if ($.browser.msie && $.browser.version <= 6) {
        var doc_h = $(body).height();
        var f_h = $("#footer").height();
        $("#footer").css({
            top: doc_h - f_h
        })
    }
    return
}
function position_popup(popup) {
    var view_height = $(window).height();
    var view_width = $(window).width();
    var bb = (!isNaN(parseInt(popup.css("borderBottomWidth")))) ? parseInt(popup.css("borderBottomWidth")) : 0;
    var bl = (!isNaN(parseInt(popup.css("borderLeftWidth")))) ? parseInt(popup.css("borderLeftWidth")) : 0;
    var br = (!isNaN(parseInt(popup.css("borderRightWidth")))) ? parseInt(popup.css("borderRightWidth")) : 0;
    var bt = (!isNaN(parseInt(popup.css("borderTopWidth")))) ? parseInt(popup.css("borderTopWidth")) : 0;
    var popup_width = popup.width() + bl + br;
    var popup_height = popup.height() + bb + bt;
    var popup_loading_left = Math.ceil((view_width - popup_width) / 2) + $(document).scrollLeft();
    var popup_loading_top = Math.ceil((view_height - popup_height) / 2) + $(document).scrollTop();
    if (view_width - popup_width - 120 < 0) {
        popup_loading_left = $(document).scrollLeft() + 100
    }
    if (view_height - popup_height < 0) {
        popup_loading_top = $(document).scrollTop() + 10
    }
    if (popup.css("position") == 'fixed') {
        var popup_loading_left = Math.ceil((view_width - popup_width) / 2);
        var popup_loading_top = Math.ceil((view_height - popup_height) / 2);
        if (view_width - popup_width - 120 < 0) {
            popup_loading_left = 100
        }
        if (view_height - popup_height < 0) {
            popup_loading_top = 10
        }
    }
    popup.css({
        left: popup_loading_left,
        top: popup_loading_top
    });
    return
}
function remove_blanket(popup, time) {
    if (time != 0) {
        popup.fadeOut(time);
        setTimeout(function () {
            $("#blanket").css({
                opacity: 0
            })
        }, time);
        setTimeout(function () {
            $("#blanket_iframe").remove()
        }, time);
        setTimeout(function () {
            $("#blanket").remove()
        }, time)
    } else {
        popup.hide();
        $("#blanket").css({
            opacity: 0
        });
        $("#blanket_iframe").remove();
        $("#blanket").remove()
    }
    return
}
function set_m_top_1() {
    var w = $("#m_top_1 .menu").width();
    var lis = $("#m_top_1 .menu > li").length;
    var li_w = 0;
    $("#m_top_1 .menu > li").each(function () {
        li_w += $(this).width()
    });
    var margin = Math.floor((w - li_w - 2) / (lis - 1));
    $("#m_top_1 .menu > li").each(function () {
        if (!$(this).is(":last-child")) {
            $(this).css({
                marginRight: margin
            })
        }
    });
    return
}
function set_m_top_2() {
    var w = $("#m_top_2 .menu").width();
    var lis = $("#m_top_2 .menu > li").length;
    var li_w = 0;
    $("#m_top_2 .menu > li").each(function () {
        li_w += $(this).width()
    });
    var margin = Math.floor((w - li_w - 2) / (lis * 2));
    $("#m_top_2 .menu > li").each(function () {
        $(this).css({
            paddingLeft: margin,
            paddingRight: margin
        })
    });
    return
}
function slide_left(clicks, max_clicks, scoll_val, elm, speed) {
    if (clicks > 0) {
        --clicks;
        $('.list_pre', elm).animate({
            scrollLeft: scoll_val * clicks
        }, speed);
        if (clicks < 1) {
            $('.nav_prev a', elm).removeClass("a")
        }
    }
    if (clicks <= max_clicks && max_clicks > 0) {
        $('.nav_next a', elm).addClass("a")
    }
    return clicks
}
function slide_right(clicks, max_clicks, scoll_val, elm, speed) {
    if (clicks < max_clicks) {
        ++clicks;
        $('.list_pre', elm).animate({
            scrollLeft: scoll_val * clicks
        }, speed);
        if (clicks >= max_clicks) {
            $('.nav_next a', elm).removeClass("a")
        }
    }
    if (clicks > 0 && max_clicks > 0) {
        $('.nav_prev a', elm).addClass("a")
    }
    return clicks
}
$(document).ready(function () {
    $('.iepng').ifixpng();
    set_m_top_1();
    set_m_top_2();
    correct_a_tab();
    $(window).bind("resize", function () {
        set_m_top_2();
        set_m_top_1();
        correct_footer_pos()
    });
    $(".lnk_blank").bind("click", function (e) {
        e.preventDefault();
        window.open($(this).attr("href"))
    });
    var date = new Date();
    var mins = (date.getMinutes() < 10) ? '0' + date.getMinutes() : date.getMinutes();
    $("#header .time .hm").text(date.getHours() + ":" + mins);
    $("#header .time .d").text(date.getDate());
    $(document).everyTime(1000, "clock", function () {
        var date = new Date();
        var mins = (date.getMinutes() < 10) ? '0' + date.getMinutes() : date.getMinutes();
        $("#header .time .hm").text(date.getHours() + ":" + mins);
        $("#header .time .d").text(date.getDate())
    });
    var imgs = new Object();
    if ($("#top_news .titles dd").length > 0) {
        var imgs = {
            tnews: new Array()
        };
        var i = 0;
        $("#top_news .titles dd").each(function () {
            if ($(".img img", $(this)).length > 0) {
                var img_w = $(".img img", $(this)).attr("width");
                var img_h = $(".img img", $(this)).attr("height");
                if ($.browser.msie) {
                    var img_w = parseInt($(".img img", $(this)).css("width"));
                    var img_h = parseInt($(".img img", $(this)).css("height"))
                }
                imgs.tnews[i] = new Array();
                imgs.tnews[i]['photo'] = $(".img img", $(this)).attr("src");
                imgs.tnews[i]['height'] = img_h;
                imgs.tnews[i]['width'] = img_w;
                imgs.tnews[i]['alt'] = $(".img img", $(this)).attr("alt")
            }++i
        })
    }
    $("#top_news .titles dt").hover(function () {
        $("#top_news .image .list .back").css({
            zIndex: -1
        });
        var parent = $(this);
        var indx = $("#top_news .titles dt").index($("#top_news .titles dt.a"));
        var indx_new = $("#top_news .titles dt").index(parent);
        var elm = $("#top_news .image .list li").eq(indx);
        var elm_new = $("#top_news .image .list li").eq(indx_new);
        if (indx != indx_new) {
            $("#top_news .titles dt").removeClass("a");
            parent.addClass("a");
            $(".blck_double .b").removeClass("b_a");
            $(".blck_double .t").removeClass("t_a");
            if (parent.hasClass("first")) {
                $(".blck_double .t").addClass("t_a")
            }
            if (parent.hasClass("last")) {
                $(".blck_double .b").addClass("b_a")
            }
            elm_new.css({
                zIndex: 2
            });
            elm.fadeOut(300, function () {
                $(this).css({
                    zIndex: 1
                });
                $(this).show();
                elm_new.css({
                    zIndex: 3
                })
            })
        }
    });
    $(".new_window").bind("click", function (e) {
        e.preventDefault();
        var href = $(this).attr("href");
        window.open(href, '', '')
    });
    $(".date_pick .input input").bind("focus", function () {
        if ($(this).val() == 'дд/мм/гггг') {
            $(this).val('')
        }
    });
    $(".date_pick .input input").bind("blur", function () {
        if ($(this).val() == '') {
            $(this).val('дд/мм/гггг')
        }
    });
    $('#main .queries .list_pre').css({
        overflow: "hidden"
    });
    var total_elms = $('#main .queries .list li').length;
    var scoll_val = 170 + 15;
    var gal_width = total_elms * scoll_val;
    var clicks = 0;
    var show_elms = 1;
    var max_clicks = total_elms - show_elms;
    $('#main .queries .list').width(gal_width);
    if (total_elms > 1) {
        $("#main .queries .nav_next a").addClass("a")
    }
    $("#main .queries .nav_prev a").bind("click", function (e) {
        e.preventDefault();
        clicks = slide_left(clicks, max_clicks, scoll_val, $("#main .queries"), 600)
    });
    $("#main .queries .nav_next a").bind("click", function (e) {
        e.preventDefault();
        clicks = slide_right(clicks, max_clicks, scoll_val, $("#main .queries"), 600)
    });
    $('#main .galleries .list_pre').css({
        overflow: "hidden"
    });
    var total_elms_1 = $('#main .galleries .list li').length;
    var scoll_val_1 = 175 + 15;
    var gal_width_1 = total_elms_1 * scoll_val_1;
    var clicks_1 = 0;
    var show_elms_1 = 1;
    var max_clicks_1 = total_elms_1 - show_elms_1;
    $('#main .galleries .list').width(gal_width_1);
    if (total_elms_1 > 1) {
        $("#main .galleries .nav_next a").addClass("a")
    }
    $("#main .galleries .nav_prev a").bind("click", function (e) {
        e.preventDefault();
        clicks_1 = slide_left(clicks_1, max_clicks_1, scoll_val_1, $("#main .galleries"), 600)
    });
    $("#main .galleries .nav_next a").bind("click", function (e) {
        e.preventDefault();
        clicks_1 = slide_right(clicks_1, max_clicks_1, scoll_val_1, $("#main .galleries"), 600)
    });
    $('.gallery .list_pre').css({
        overflow: "hidden"
    });
    var total_elms_2 = $('.gallery .list li').length;
    var scoll_val_2 = 64 + 10;
    var gal_width_2 = total_elms_2 * scoll_val_2 - 10;
    var clicks_2 = 0;
    var show_elms_2 = 4;
    var max_clicks_2 = Math.ceil((total_elms_2 - show_elms_2) / 4);
    $('.gallery .list').width(gal_width_2);
    if (total_elms_2 > show_elms_2) {
        $(".gallery .nav_next a").addClass("a")
    }
    $(".gallery .nav_prev a").bind("click", function (e) {
        e.preventDefault();
        clicks_2 = slide_left(clicks_2, max_clicks_2, scoll_val_2 * 4, $(".gallery"), 400)
    });
    $(".gallery .nav_next a").bind("click", function (e) {
        e.preventDefault();
        clicks_2 = slide_right(clicks_2, max_clicks_2, scoll_val_2 * 4, $(".gallery"), 400)
    });
    $("#video .list a").bind("click", function (e) {
        e.preventDefault();
        if (!$(this).parents("li").hasClass("a")) {
            $(".video", $(this).parents("li")).show();
            $(this).parents("li").addClass("a");
            var view_h = $(window).height();
            var elm_h = $(this).parents("li").height();
            var offset_t = $(this).parents("li").offset().top;
            var top = Math.ceil((view_h - elm_h) / 2);
            if (view_h - elm_h < 0) {
                top = 10
            }
            $("html, body").animate({
                scrollTop: offset_t - top
            }, 600)
        } else {
            $(".video", $(this).parents("li")).hide();
            $(this).parents("li").removeClass("a")
        }
    });
    $("#main .left .tags input").each(function () {
        $(this).css({
            left: 0,
            opacity: 0,
            zIndex: -1,
            position: "absolute",
            top: 0
        })
    });
    $("#main .left .tags input").each(function () {
        if ($(this).is(":checked")) {
            $(this).parent("li").addClass("a")
        }
    });
    $("#main .left .tags input").bind("click", function () {
        if ($(this).is(":checked")) {
            $(this).parent("li").addClass("a")
        } else {
            $(this).parent("li").removeClass("a")
        }
    });
    $("#main .left .tags label")._hover(function () {
        $(this).addClass("hover")
    }, function () {
        $(this).removeClass("hover")
    });
    $(".tags li a")._hover(function () {
        $(this).parent("li").addClass("hover")
    }, function () {
        $(this).parent("li").removeClass("hover")
    });
    $(".feedback a").bind("click", function (e) {
        e.preventDefault();
        var args = new Object();
        args = {
            "type": "window",
            "opacity": .2
        };
        cast_blanket($("#ww_feedback"), 0, args)
    });
    $("#ww_feedback .close a").bind("click", function (e) {
        e.preventDefault();
        remove_blanket($("#ww_feedback"), 0)
    });
    $("#ww_feedback .textarea textarea").each(function () {
        check_str_lngth($(this), 1600, ".input")
    });
    $("#ww_feedback .textarea textarea").bind("keyup click change", function (e) {
        check_str_lngth($(this), 1600, ".input")
    });
    $("#gallery .list li a")._hover(function (e) {
        var b_elm = $(".balloon", $(this).parents("li"));
        var pic_off_x = $(this).offset().left - $(this).parents("li").offset().left;
        var pic_off_y = $(this).offset().top - $(this).parents("li").offset().top;
        var pos_x = e.clientX - $(this).offset().left - (b_elm.width() / 2 - pic_off_x) - $(document).scrollLeft();
        var pos_y = e.clientY - $(this).offset().top - (b_elm.height() + 16 - pic_off_y) - $(document).scrollTop();
        b_elm.css({
            left: pos_x,
            top: pos_y
        });
        b_elm.show();
        $(this).bind("mousemove", function (e) {
            var pos_x = e.clientX - $(this).offset().left - (b_elm.width() / 2 - pic_off_x) + $(document).scrollLeft();
            var pos_y = e.clientY - $(this).offset().top - (b_elm.height() + 16 - pic_off_y) + $(document).scrollTop();
            b_elm.css({
                left: pos_x,
                top: pos_y
            })
        })
    }, function (e) {
        var b_elm = $(".balloon", $(this).parents("li"));
        $(this).unbind("mousemoce");
        b_elm.hide()
    });
    if ($("#gallery .list li").length > 0) {
        var imgs = {
            gallery: new Array()
        };
        var i = 0;
        $("#gallery .list li").each(function () {
            if ($(".photo img", $(this)).length > 0) {
                var img_w = $(".photo img", $(this)).attr("width");
                var img_h = $(".photo img", $(this)).attr("height");
                if ($.browser.msie) {
                    img_w = parseInt($(".photo img", $(this)).css("width"));
                    img_h = parseInt($(".photo img", $(this)).css("height"))
                }
                imgs.gallery[i] = new Array();
                imgs.gallery[i]['photo'] = $(".photo img", $(this)).attr("src");
                imgs.gallery[i]['height'] = img_h;
                imgs.gallery[i]['width'] = img_w;
                imgs.gallery[i]['title'] = $(".photo img", $(this)).attr("title")
            }++i
        })
    }
    $("#gallery .list li a").bind("click", function (e) {
        e.preventDefault();
        var elm = $(this).parents("li");
        var indx = $("#gallery .list li").index($(this).parents("li"));
        var args = new Object();
        args = {
            "type": "img",
            "opacity": .7,
            "list": imgs.gallery,
            "indx": indx,
            "total": $("#gallery .list li .photo").length
        };
        console.log(args);
        cast_blanket($("#ww_photo"), 400, args)
    });
    if ($(".gallery .list li").length > 0) {
        var imgs = {
            ingallery: new Array()
        };
        var i = 0;
        $(".gallery .list li").each(function () {
            if ($(".photo img", $(this)).length > 0) {
                var img_w = $(".photo img", $(this)).attr("width");
                var img_h = $(".photo img", $(this)).attr("height");
                if ($.browser.msie) {
                    img_w = parseInt($(".photo img", $(this)).css("width"));
                    img_h = parseInt($(".photo img", $(this)).css("height"))
                }
                img_w = (img_w > 0) ? img_w: 600;
                img_h = (img_h > 0) ? img_h: 450;
                imgs.ingallery[i] = new Array();
                imgs.ingallery[i]['photo'] = $(".photo img", $(this)).attr("src");
                imgs.ingallery[i]['height'] = img_h;
                imgs.ingallery[i]['width'] = img_w;
                imgs.ingallery[i]['title'] = $(".photo img", $(this)).attr("title")
            }++i
        })
    }
    $(".gallery .list li a").bind("click", function (e) {
        e.preventDefault();
        var elm = $(this).parents("li");
        var indx = $(".gallery .list li").index($(this).parents("li"));
        var args = new Object();
        args = {
            "type": "img",
            "opacity": .7,
            "list": imgs.ingallery,
            "indx": indx,
            "total": $(".gallery .list li .photo").length
        };
        cast_blanket($("#ww_photo"), 400, args)
    });
    $("#ww_photo .close a").bind("click", function (e) {
        e.preventDefault();
        remove_blanket($("#ww_photo"), 0)
    });
    $(document).bind("keydown", function (e) {
        if (e == null) {
            var keycode = e.keyCode
        } else {
            var keycode = e.which
        } if (keycode == 27) {
            remove_blanket($("#ww_photo"), 0);
            remove_blanket($("#ww_feedback"), 0)
        }
    }); /*$("#video .player").each(function(){$(this).flowplayer("/sites/all/themes/pskov/flowplayer-3.1.5.swf",$(this).attr("title"))});*/
    $("#ww_feedback :submit").bind("click", function (e) {
        var form = $("#ww_feedback");
        var frms = {
            subj: $("input[name=submitted[subj]]", form),
            email: $("input[name=submitted[email]]", form),
            msg: $("textarea[name=submitted[msg]]", form),
            frm_captcha: $("input[name=captcha_response]", form)
        };
        e.preventDefault();
        var errors = new Array();
        $.each(frms, function (field, input) {
            if (input.val() == '') {
                input.parents("li").addClass("error");
                errors.push(field)
            } else if (field == "email" && !/^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9-_])+\.([a-z0-9]{2,4})$/.test(input.val())) {
                errors.push(field)
            } else {
                input.parents("li").removeClass("error")
            }
        });
        if (errors.length == 0) {
            $("#ww_feedback :submit").attr({
                disabled: "disabled"
            });
            $.ajax({
                type: "post",
                url: "/sites/all/themes/pskov/js_feedback.php",
                dataType: 'json',
                data: $("form", form).serialize(),
                success: function (json) {
                    if (json.errors == 0) {
                        $("form", form).remove();
                        $(".info", form).remove();
                        $("<div />").css({
                            color: "#000",
                            font: "12px arial",
                            position: "relative",
                            margin: "32px 0"
                        }).text("Ваще сообщение отправлено.").appendTo($(".above", form));
                        $.each($(".input :input", form), function () {
                            $(this).val('')
                        })
                    } else {
                        $.each($("li", form), function () {
                            $(this).removeClass("error")
                        });
                        $.each(json.errors, function (num, field) {
                            $("input[name=" + field + "]", form).parents("li").addClass("error")
                        });
                        $("#ww_feedback :submit").attr({
                            disabled: ""
                        })
                    }
                },
                error: function (obj, txt, err) {
                    alert("Во время отправки произошла ошибка.")
                }
            })
        }
    });
    var tid = 0;
    tid = $("#frm_d_theme option:selected").val();
    if ($(".dsub" + tid).length == 1) {
        $(".dsub" + tid).show()
    } else if (tid == 0) {
        $(".dsub").hide()
    }
    $("#frm_d_theme").bind("change", function () {
        var tid = 0;
        tid = $(this).val();
        if ($(".dsub" + tid).length == 1) {
            $(".dsub").slideUp(300, function () {
                $(".dsub" + tid).slideDown(300)
            })
        } else {
            $(".dsub").slideUp(300)
        }
    });
    $("#documents .dsub select").bind("change", function () {
        $("#dsub_active").val($(this).val())
    });
    $.datepicker.setDefaults($.datepicker.regional['ru']);
    $.datepicker.setDefaults({
        showAnim: 'fadeIn'
    });
    $("#frm_date_s").datepicker({
        dateFormat: 'dd/mm/yy'
    });
    $("#frm_date_e").datepicker({
        dateFormat: 'dd/mm/yy'
    })
});