$(document).ready(
    function() {

        $(window).load(setColumns);
        $(window).resize(setColumns);

        $("a.left-tabs-one").click(
            function() {
                $("div.left-tabs-top").removeClass("left-tabs-top-active");
                $("div.left-tabs-content-one").css("display", "block");
                $("div.left-tabs-content-two").css("display", "none");

                return false;
            }
        );

        $("a.left-tabs-two").click(
            function() {
                $("div.left-tabs-top").addClass("left-tabs-top-active");
                $("div.left-tabs-content-one").css("display", "none");
                $("div.left-tabs-content-two").css("display", "block");

                return false;
            }
        );

        $("a.main-tabs-one").click(
            function() {
                $("div.main-tabs-top").removeClass("main-tabs-top-two main-tabs-top-three");
                $("div.main-tabs-content-one").css("display", "block");
                $("div.main-tabs-content-two").css("display", "none");
                $("div.main-tabs-content-three").css("display", "none");

                return false;
            }
        );

        $("a.main-tabs-two").click(
            function() {
                $("div.main-tabs-top").removeClass("main-tabs-top-three").addClass("main-tabs-top-two");
                $("div.main-tabs-content-one").css("display", "none");
                $("div.main-tabs-content-two").css("display", "block");
                $("div.main-tabs-content-three").css("display", "none");

                return false;
            }
        );

        $("a.main-tabs-three").click(
            function() {
                $("div.main-tabs-top").removeClass("main-tabs-top-two").addClass("main-tabs-top-three");
                $("div.main-tabs-content-one").css("display", "none");
                $("div.main-tabs-content-two").css("display", "none");
                $("div.main-tabs-content-three").css("display", "block");

                return false;
            }
        );

        $("span.checkbox").each(
            function() {
                curSpan = $(this);
                curCheckbox = curSpan.find("input");
                if (curCheckbox.attr("checked")) {
                    curSpan.addClass("checkbox-active");
                    if (curSpan.hasClass("edit-profile")) {
                        $("div.cabinet-edit-profile").show();
                    }
                }
                curSpan.bind("click",
                    function() {
                        var curSpan = $(this);
                        var curCheckbox = curSpan.find("input");
                        curSpan.toggleClass("checkbox-active");
                        if (curSpan.hasClass("checkbox-active")) {
                            curCheckbox.attr("checked", "checked")
                            if (curSpan.hasClass("edit-profile")) {
                                $("div.cabinet-edit-profile").show();
                            }
                        } else {
                            curCheckbox.removeAttr("checked");
                            if (curSpan.hasClass("edit-profile")) {
                                $("div.cabinet-edit-profile").hide();
                            }
                        }
                    }
                );
            }
        );

        var curSelectRel = 1;
        var curSelectZ = 100;

        $(".registration-select select").each(
            function() {
                var curSelect = $(this);
                curSelect.parent().parent().css("z-index", curSelectZ--);
                curSelect.attr("rel", curSelectRel++).niceSelect();
            }
        );

        $("div.registration-subscribe input.btn-select-all").click(
            function() {
                $("div.registration-subscribe span.checkbox").each(
                    function() {
                        curSpan = $(this);
                        curCheckbox = curSpan.find("input");
                        curSpan.addClass("checkbox-active");
                        curCheckbox.attr("checked", "checked")
                    }
                );
            }
        );

        $("div.registration-subscribe input.btn-select-none").click(
            function() {
                $("div.registration-subscribe span.checkbox").each(
                    function() {
                        curSpan = $(this);
                        curCheckbox = curSpan.find("input");
                        curSpan.removeClass("checkbox-active");
                        curCheckbox.removeAttr("checked")
                    }
                );
            }
        );

        $("span.radio").each(
            function() {
                curSpan = $(this);
                curCheckbox = curSpan.find("input");
                if (curCheckbox.attr("checked")) {
                    curSpan.addClass("radio-active");
                }
                curSpan.bind("click",
                    function() {
                        var curSpan = $(this);
                        var curCheckbox = curSpan.find("input");
                        curName = curCheckbox.attr("name");
                        curCheckbox.attr("checked", "checked");
                        $("span.radio input[name=" + curName + "]").each(
                            function() {
                                $(this).parent().removeClass("radio-active");
                            }
                        );
                        curSpan.addClass("radio-active");
                    }
                );
            }
        );

        $("div.rates-links h3 a").click(
            function() {
                $(this).parent().parent().find("div").toggle();
                return false;
            }
        );

        $("div.registration-input-file input").change(
            function() {
                $(this).parent().find("span").html($(this).val());
            }
        );

        var idIE6 = 1;

        $("ul.header-menu li").each(
            function() {
                if ($.browser.msie && $.browser.version < "8.0") {
                    $(this).find("div.header-submenu").css("display", "block");
                    var curWidth = $(this).find("div.header-submenu").width();
                    $(this).find("div.header-submenu-top-left").width(curWidth - $(this).find("div.header-submenu-top").css("padding-right").replace(/px/, ""));
                    $(this).find("div.header-submenu-top").css("background-position", (curWidth - $(this).find("div.header-submenu-top").css("padding-right").replace(/px/, "")) + "px top");
                    $(this).find("div.header-submenu-items").width(curWidth - 19);
                    $(this).find("div.header-submenu-footer").width(curWidth - 32);
                    $(this).find("div.header-submenu-footer-right").css("background-position", (curWidth - 16) + "px top");
                    if ($.browser.msie && $.browser.version == "6.0") {
                        $(this).attr("id", "ieIE6" + idIE6);
                        DD_belatedPNG.fix("#ieIE6" + idIE6 + " .header-submenu-top," +
                                          "#ieIE6" + idIE6 + " .header-submenu-top-left," +
                                          "#ieIE6" + idIE6 + " .header-submenu-top-left img," +
                                          "#ieIE6" + idIE6 + " .header-submenu-items," +
                                          "#ieIE6" + idIE6 + " .header-submenu-items-right," +
                                          "#ieIE6" + idIE6 + " .header-submenu-items-left," +
                                          "#ieIE6" + idIE6 + " .header-submenu-footer-left," +
                                          "#ieIE6" + idIE6 + " .header-submenu-footer-right," +
                                          "#ieIE6" + idIE6 + " .header-submenu-footer"
                                          );
                        idIE6++;
                    }
                    $(this).find("div.header-submenu").removeAttr("style");
                }
            }
        );

        $("ul.header-menu li").mouseout(
            function() {
                $(this).find("div.header-submenu").removeAttr("style");
            }
        );

        $("ul.header-menu li").mousemove(
            function(e) {
                var curX = e.pageX;
                var curY = e.pageY;
                var offset = $(this).find("div.header-submenu").offset();
                var blockX = offset.left;
                var blockY = offset.top;
                var blockWidth = $(this).find("div.header-submenu").width();
                var blockPadding = $(this).find("div.header-submenu-top").css("padding-right").replace(/px/, "");
                if (((curX - blockX) < (blockWidth - blockPadding + 15)) && ((curY - blockY) < 34)) {
                    $(this).find("div.header-submenu").hide();
                }
            }
        );

        $("div.login-checkbox").each(
            function() {
                curDiv = $(this);
                curCheckbox = curDiv.find("input");
                if (curCheckbox.attr("checked")) {
                    curDiv.addClass("login-checkbox-active");
                }
                curDiv.bind("click",
                    function() {
                        var curDiv = $(this);
                        var curCheckbox = curDiv.find("input");
                        curDiv.toggleClass("login-checkbox-active");
                        curCheckbox.attr("checked", "checked");
                        if (curDiv.hasClass("login-checkbox-active")) {
                            curCheckbox.attr("checked", "checked")
                        } else {
                            curCheckbox.removeAttr("checked");
                        }
                    }
                );
            }
        );

        $("div.login-link").hover(
            function() {
                $("div.login").show();
                return false;
            },
            function() {
                $("div.login").hide();
            }
        );

    }
);

function setColumns() {
    if ($(window).width() > 1550) {
        $("div.wrapper").removeClass("wrapper-mini");
        $("div.footer").removeClass("footer-mini");
    } else {
        $("div.wrapper").addClass("wrapper-mini");
        $("div.footer").addClass("footer-mini");
    }
}
