function ShowImageColor(val) {

    document.images["ImageColor"].src = val;


}

var Clock = {

    options:{
        delayMin:1, // в секундах
        delayMax:1   // та же фигня
    },

    delay:0,
    rng:0,

    SetTime:function () {
        var daysOfWeek = ["Воскресенье", "Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота"];
        var months = ["января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря"];
        var currentDate = new Date();
        var mins = currentDate.getMinutes();
        if (mins < 10)
            mins = '0' + mins;
        with (Utils) {
            SetText('time', currentDate.getHours() + '<span id="blink">:</span>' + mins);
            SetText('day', currentDate.getDate() + ' ' + months[currentDate.getMonth()] + ', ' + daysOfWeek[currentDate.getDay()]);
            //SetText('day', daysOfWeek[currentDate.getDay()]);
        }
        if (currentDate.getSeconds() % 2 == 0)
            document.getElementById("blink").style.visibility = 'hidden';
        else
            document.getElementById("blink").style.visibility = 'visible';
    },

    Start:function () {
        Clock.SetTime();
        this.rng = this.options.delayMax - this.options.delayMin;
        this.delay = (this.options.delayMin + this.rng * Math.random()) * 1000;

        setInterval(
            function () {
                Clock.SetTime();
            },
            this.delay
        );
    }
};

var Utils = {
    ReturnObjById:function (id) {
        return document.getElementById ? document.getElementById(id) : document.all ? document.all[id] : document.layers[id];
    },
    SetText:function (id, txt) {
        var container = this.ReturnObjById(id);
        container.innerHTML = txt;
    },
    XmlHttp:function () {
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (E) {
                xmlHttp = false;
            }
        }
        if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
            xmlHttp = new XMLHttpRequest();
        }
        return xmlHttp;
    }
};

window.onload = function () {
    // часики пошли
    Clock.Start();

};
$(function () {
    $('.two-column').each(function () {
        var max = 0;
        $(this).children().each(function () {
            if ($(this).children().height() * 1 > max * 1) {
                max = $(this).children().height();
            }
            //alert($(this).children().height());
        });
        //alert(max);
        $(this).children().each(function () {
                   $(this).children().height(max);
        });
    });

    $('.expanded-block').mouseenter(function () {

        $(this).animate(
            {
                left:'20px'
            },
            {
                step:function (now, fx) {
                    $(this).css('height', Math.round(now));

                    var curH = Math.round(20 + 70 - now);

                    $('.expanded-block_current').css('height', curH + 'px');

//                    var data = fx.prop + ': ' + now + '&nbsp;&nbsp;&nbsp; curH: ' + curH + '&nbsp;&nbsp;&nbsp; total: ' + (now + curH);
//                    $('body').append('<div>' + data + '</div>');
                },
                duration:200
            }
        );
    });

    /*$('.auto-info-wrap .small-rounded-block').click(function(){

     if($(this).hasClass('small-rounded-block_solid-gray')) {

     $(this).removeClass('small-rounded-block_solid-gray').addClass('small-rounded-block_gradient-gray');

     $(this).find('.arrows-up').removeClass('arrows-up').addClass('arrows-down');
     }
     else {
     $(this).removeClass('small-rounded-block_gradient-gray').addClass('small-rounded-block_solid-gray');

     $(this).find('.arrows-down').removeClass('arrows-down').addClass('arrows-up');
     }

     $(this).find('.auto-info-description').slideToggle('fast');

     });*/

    $('.auto-info-wrap .small-rounded-block').click(function () {

        if ($(this).hasClass('small-rounded-block_solid-gray') || ($('.auto-info-wrap .auto-info-description:animated').length == 1)) {
            return;
        }

        var infoMaxHeight = 0;
        var elemHeight = 0;

        $('.auto-info-wrap .auto-info-description').each(function (key, value) {

            elemHeight = $(value).height('auto').height();
            $(value).height('0');
            infoMaxHeight = Math.max(infoMaxHeight, elemHeight);
        });

        currentInfo = $('.auto-info-wrap .small-rounded-block_solid-gray .auto-info-description');

        $(this).find('.auto-info-description').animate(
            {
                height:infoMaxHeight
            },
            {
                step:function (now, fx) {
                    currentInfo.css('height', (infoMaxHeight - now) + 'px');
                },
                duration:300
            }
        );

        $('.auto-info-wrap .small-rounded-block_solid-gray').removeClass('small-rounded-block_solid-gray').addClass('small-rounded-block_gradient-gray').find('.arrows-up').removeClass('arrows-up').addClass('arrows-down').parents('.small-rounded-block').find('.block-left-bottom-icon').fadeOut(200);

        $(this).removeClass('small-rounded-block_gradient-gray').addClass('small-rounded-block_solid-gray').find('.arrows-down').removeClass('arrows-down').addClass('arrows-up').parents('.small-rounded-block').find('.block-left-bottom-icon').fadeIn(200);
    });


    $("#slider-range-min").slider({
        range:"min",
        value:12,
        min:10,
        max:84,
        slide:function (event, ui) {
            $("#amount").val(ui.value);
            CalculationOfCredit();
        }
    });
    $("#amount").val($("#slider-range-min").slider("value"));

    $("#slider-range").slider({
        range:true,
        step:10000,
        min:350000,
        max:4500000,
        values:[ 350000, 3000000 ],
        slide:function (event, ui) {
            $('#budget-from').text(ui.values[0]);
            $('#budget-to').text(ui.values[1]);
            filterbyprice(ui.values[0], ui.values[1]);
        }
    });
    $('#budget-from').text($("#slider-range").slider("values", 0));
    $('#budget-to').text($("#slider-range").slider("values", 1));
    $('.fancybox').fancybox();
    $('.car-type-select input[type="checkbox"], .ride-type-select input[type="checkbox"], .roominess-select input[type="checkbox"]').change(function () {

        $(this).parents('td').toggleClass('selected');
    });

    $('.cars-compare-group').hover(
        function () {
            if (!$(this).hasClass('cars-compare-group_closed')) {
                return false;
            }
            $(this).toggleClass('cars-compare-group_hover');
        },
        function () {
            if (!$(this).hasClass('cars-compare-group_closed')) {
                return false;
            }
            $(this).toggleClass('cars-compare-group_hover');
        }
    );

    /* $('.cars-compare-group').click(function() {
     $(this).toggleClass('cars-compare-group_hover').toggleClass('cars-compare-group_closed');
     });
     */
    $(".cars-compare-group").delegate("", "click", function () {
        $(this).toggleClass('cars-compare-group_hover').toggleClass('cars-compare-group_closed');

    });
    $('.collapsing-header span').click(function () {

        if ($(this).parent().hasClass('collapsing-header_active')) {
            $(this).parent().removeClass('collapsing-header_active');
            $('.collapsing-body').slideUp();
        }
        else {
            $('.collapsing-header').removeClass('collapsing-header_active');
            $('.collapsing-body').slideUp();

            $(this).parent().toggleClass('collapsing-header_active').next('.collapsing-body').slideToggle();
        }
    });

    $('.auto-complect-title a').click(function () {

        $(this).parent().next().slideToggle();

        return false;
    });

    $('.fieldset-list .pseudo-link').click(function (e) {
        e.preventDefault();
        if (!$(this).next('.fieldset-list-options-descr').size()) return false;
        $(this).toggleClass('pseudo-link_active').next('.fieldset-list-options-descr').toggle();
    })
});
function ResetCaptcha() {
    $.get('/resetcaptcha.php', function (data) {
        var html = ' <input type="hidden" name="captcha_sid" value="' + data + '"><img src="/bitrix/tools/captcha.php?captcha_sid=' + data + '" alt="CAPTCHA">';
        $("#captcha").html(html);

        //  alert(data);
    });
    return false;
}
function Cheked() {
    var count = 0;
    $(".auto-complect-title .i-chckbx:checked").each(function () {
        count++;
    });
    if (count == 3) {
        $(".auto-complect-title .i-chckbx").each(function () {
            if ($(this).attr("checked") != 'checked')
                $(this).attr("disabled", "disabled");
            //     alert($(this).attr("checked"));
        });
    }

    if (count < 3) {
        $(".auto-complect-title .i-chckbx").each(function () {
            if ($(this).attr("disabled") == 'disabled') {
                $(this).attr("disabled", "");
                $(this).removeAttr("disabled");
            }
            //     alert($(this).attr("checked"));
        });
    }
}
function SelecModels(id_s, id_c) {
    var id = $("#" + id_s + " :selected").attr("id");
    //alert(id);

    if (id != "") {
        $.get('/ajax/model.php?IBLOCK_ID=1&SECTION_ID=' + id, function (data) {
            $('#' + id_c).html(data);
            //  alert(data);
        });
    }
}
function SelectComplects(id_s, id_c) {
    var id = $("#" + id_s + " :selected").attr("id");
    if (id != "") {
        $.get('/ajax/camplect.php?IBLOCK_ID=1&SECTION_ID=' + id, function (data) {
            $('#' + id_c).html(data);
            //  alert(data);
        });


    }
}
function Comparecount() {
    var count = 0;
    var mas = Array();
    $(".qwertrt .selects :selected").each(function () {
        if ($(this).val() != 0) {
            count++;
            mas[count] = $(this).attr("rel");

        }
        //alert($(this).val());
    });
    if (count >= 2) {
        var getparams = "?";
        for (i = 1; i <= count; i++) {
            if (i == count)
                getparams = getparams + "id[" + i + "]=" + mas[i];
            else
                getparams = getparams + "id[" + i + "]=" + mas[i] + "&";
        }
        $.get('/ajax/comparison.php' + getparams, function (data) {
            $('#resultcompare').html(data);
            //  alert(data);
        });

        //alert(getparams)
    }
}

function Selectusedcars() {
    var id = $("#addusedcarsmodel :selected").attr("value");
    if (id != "") {
        $.get('/ajax/modelvalid.php?IBLOCK_ID=37&SECTION_ID=' + id, function (data) {
            $('#usedcarsmodel').html(data);
            //  alert(data);
        });


    }
}
function SerchGallery() {
    var parentcode = $("#marka :selected").attr("value");
    var code = $("#model :selected").attr("rel");
    //alert(parentcode+"____"+code);
    if (parentcode != '' && code != "") {
        location.href = "/catalog/" + parentcode + "/" + code + "/gallery/";
    }
}


function Comaparsionclick() {
    var count = 0;
    var mas = Array();

    $(".auto-complect-title .i-chckbx:checked").each(function () {
        count++;
        mas[count] = $(this).val();
    });
    if (count >= 2) {
        var getparams = "?";
        for (i = 1; i <= count; i++) {
            if (i == count)
                getparams = getparams + "id[" + i + "]=" + mas[i];
            else
                getparams = getparams + "id[" + i + "]=" + mas[i] + "&";
        }
        $.get('/ajax/comparison.php' + getparams, function (data) {
            //$('#resultcompare').html(data);
            //  alert(data);
            //location.href = "/comparison_full/";
            //  getTopWin (). getBrowser (). addTab ("http://new.gs-trade.ru/comparison_full/");
            window.open("http://www.gs-trade.ru/comparison_full/", "_blank");
        });
    }

}


