$(document).ready(function() {
//работа с корзиной ------------------------------------------------------------
    $("div.cart_no_js").hide();
    $("input.input[name=addgoods]").hide();
    $("span.goods_cart_delete").show();
    $("div.cart_js").html('<span class="add_in_cart" style="color: #1A3DC1; cursor: pointer">Добавить в корзину</span>');
    //добавление в корзину
    $(".add_in_cart").click(function() {
        var where_is = $(this).parents("form").attr("class");
        if(where_is == "info") {
            var count_f = $("input.count").attr("name");
            var price_f = $("input.price").attr("name");
            var price = $("input.price").attr("value");
        } else {
            var goods = $(this).parents(".goods_cart_count");
            var count_f = $(goods).find("input.count").attr("name");
            var price_f = $(goods).find("input.price").attr("name");
            var price = $(goods).find("input.price").attr("value");
        }
        $(goods).find(".cart_js").html("подождите...");
        $.ajax({
            type: "POST",
            url: "/cart.php",
            data: "addgoods=true&"+count_f+"=1&"+price_f+"="+price,
            success: function() {
                $(goods).find("div.cart_js").html('Уже в <a href="/cart.php" style="color: #1A3DC1">корзине</a>');
            }
        });
    });
    //удаление из корзины
    $(".goods_cart_delete").click(function() {
        $(this).text("").prepend("<img src='/img/load.gif' alt='...' />");
        var goods = $(this);
        var goods_id = $(this).attr("id");
        var formaoplati = $("input[name=formaoplati]:checked").val();
        if(confirm("Удалить товар?") == true) {
            $.ajax({
                type: "POST",
                url: "/cart.php",
                data: "recount=true&"+goods_id+"=0&formaoplati="+formaoplati,
                success: function(answer) {
                    $(goods).parents(".goods_cart").fadeTo(1000, 0.2, function() {
                        $(goods).parents(".goods_cart").slideUp(1000);
                        $(goods).parents(".goods_cart").find("input.count").attr("value", "0");
                    });
                    recount_cart_price(answer);
                }
            });
        } else $(this).text("удалить");
    });
    //пересчет суммы стоимости товара в корзине
    function recount_cart_price(answer) {
        $("span#sum_ue").html($(answer).find("span#sum_ue").text());
        $("span#sum_rub").html($(answer).find("span#sum_rub").text());
        $("span#sum").html($(answer).find("span#sum").text());
    }

//изображения товара -----------------------------------------------------------
    if($(".small_img").length) {
        $(".small_img").parent("a").removeAttr("href");
        var format_img_size = $(".format_img").attr("src").match("\&size=([0-9]*)\&");
        if(format_img_size) format_img_size = format_img_size[1];
            else format_img_size = 300;
        var small_img_size = $(".small_img").attr("src").match("\&size=([0-9]*)\&");
        if(small_img_size) small_img_size = small_img_size[1];
            else small_img_size = 60;
        //бордер для мини-изображений при наведении
        $(".small_img").hover(function() {
            $(this).css("border-color", "#42618C");
        }, function() {
            $(this).css("border-color", "#FFFFFF");
        });
        //вывод увеличенного изображения при клике
        $(".small_img").click(function() {
            var clicked = $(this);
            $("img.format_img").fadeOut(500, function() {
                $(this).attr("src", $(clicked).attr("src").replace("size="+small_img_size, "size="+format_img_size)).fadeIn(500);
            })
        });
    }
    if($("img.small_img:hidden").length) {
        $("#show_more_pic").show();
        $("#show_more_pic").click(function() {
            $(this).hide();
            $("img.small_img:hidden").fadeIn(2000);
        });
    }
//нулевая цуна -----------------------------------------------------------------
    if($("span.retail_price").size()) {
        if($("span.retail_price").html() == "0.00") $("form.info").hide().parent("td").html("<b>Нет в наличии</b>");
    }
});