/* делаем красиво чекбоксам формы ya_form */
function nice()
{
    var form = document.getElementById('ya_form');
    if (!form) return;
    if (form.className.indexOf('nice')+1) return;
    form.className += ' nice';
    
    var checks = form.getElementsByTagName('label');
    for (var i=0; i<checks.length; i++)
    {
        var curr = checks[i];
        var box  = curr.firstChild;
        box.className = 'lost';
        
        curr.className += box.type;
        curr.className += (box.checked) ? '-on' : '-off';
        
        box.onchange = function()
        {
            var label = this.parentNode;
            if (this.type == 'checkbox')
            {
                label.className = (this.checked) ? label.className.replace('-off','-on') : label.className.replace('-on','-off');
                showFlats(this);
            }
        }
    }
}


function filter_radio_select() {
    $('.filter_form .with_radio select, .filter_form .with_radio .text ').attr('disabled','disabled');
    $('.filter_form .with_radio .radio:checked').parents('.with_radio').find('.target').removeAttr("disabled");

    $('.filter_form .radio').die('change.radio_select').live('change.radio_select', function(){
        var name = $(this).attr('name');
        $('.filter_form .radio[name]='+name).parents('.with_radio').find('.target').attr('disabled','disabled')
        $('.filter_form .radio[name]='+name+':checked').parents('.with_radio').find('.target').removeAttr("disabled");
    });
}

$(document).ready(function(){
    
    $('.filter_form').jqTransform();
    filter_radio_select();
    
    $('.filter_form').bind('keydown', function (event) {
        if (event.which==13) { // сабмитим по Enter в пределах формы
            $(this).filter('form').submit();
        }
    });
    
    $('#filter_simple a.switcher_link').click(function(){
        $('#filter_simple').hide();
        $('#filter_advanced').show();
        $('.filter_form').jqTransform();
        return false;
    });

    $('#filter_advanced a.switcher_link').click(function(){
        $('#filter_advanced').hide();
        $('#filter_simple').show();
        $('.filter_form').jqTransform();
        return false;
    });
    

        $('#ya-map .ya-pin-cost').click(function(){
            $('#ya-map .ya-pin-info').hide('fast');
            $('#ya-map .ya-pin-cost').show('fast');
            $(this).hide().parent().find('.ya-pin-info').show('fast');
        });
        $('#ya-map .ya-pin-info .ya-pin-close').click(function(){
            $(this).parent().hide('fast').prev().show('fast');
            });

        var item_height = 0;
        for(var i=0; i <= $('.hotel_main_block').children('.item').length; i++)
        {
            if(i == $('.hotel_main_block').children('.item').length)
            {
                $('.hotel_main_block').children('.item').height(item_height);
            } 
            else
            {
                var temp_height = $($('.hotel_main_block').children('.item')[i]).height();
                item_height = (item_height < temp_height) ? temp_height : item_height;
            }
        }
            
    nice();

});


if ( !Array.prototype.forEach ) { // добавляем функцию, поддерживаемую не всеми браузерами
    Array.prototype.forEach = function(fn, thisObj) {
        var scope = thisObj || window;
        for ( var i = 0, len = this.length; i < len; ++i ) {
            fn.call(scope, this[i], i, this);
        }
    };
}

