$(function() {
    $('.vmenu > ul > li:has(ul)').children('a').attr('href','javascript:void(0)').css('text-decoration','none');
    $('form a.button').bind('click', function() {
        $($(this).parents('form')[0]).submit();
        return false;
    });
    
    $('div.calc .tocart, .cart .tbuttons .tocart:first, .order-form .tocart').bind('click', function() {
        $($(this).parents('form')[0]).submit();
        return false;
    });
    
    $('input.qty').bind('keyup', function() {
        qty = 0;
        if($(this).val()) {
           qty = parseInt($(this).val());
        }
        $('input.sum').val(parseInt($('#cena').text())*qty);
    });
    
    $("a[rel='colorbox']").colorbox();

    $('.popular tr:last td').addClass('last');
    
    $('.inp-search').bind({
       'focusin' : function() {
           if($(this).val() == 'поиск') {
               $(this).val('');
           }
       },
       'focusout' : function() {
           if(!$(this).val()) {
               $(this).val('поиск');
           }
       }
    });
    
    var txt='';
    $('input.inp2, input.inp3').bind({
        'focusin' : function() {
            if($(this).val() == 'Улица' || $(this).val() == 'Дом' || $(this).val() == 'Кв.') {
                txt=$(this).val()
                $(this).val('');
            }
        },
        'focusout' : function() {
            if(!$(this).val()) {
                $(this).val(txt);
            }
        }
    });
    
    $('a.sel-button').bind('click', function(e) {
        e.stopPropagation();
        $('div.select-window').hide();
        $(this).siblings('.select-window').toggle();
        return false;
    });
    
    $('div.select-window a').bind('click', function() {
        $(this).parents('.select-window').siblings('input').val($(this).text()).end().hide();
    });
    
    $(document).bind('click',function() {
        $('div.select-window').hide();
    });
});
