/**
 * Селектор образцов
 * added: Viodele [13.10.11]
 */
$(function() {
    $('li.sortir').click(function () {
        var li = $(this);
        var a = $(this).find('a');
        var cat = a.attr('href').replace(/^\#cat/, '');
        
        $('li.sortir').each(function () {
            $(this).removeClass('sortir_active');
        });
        li.addClass('sortir_active');
        
        $('tr.folio').each(function () {
            $(this).css('display', 'none');
        });

        switch (cat) {
            case '2011':
            case '2010':
            case '2009':
            case 'Logo':
            case 'Locked':
            case 'Design':
            case 'Shop':
                $('tr.cat' + cat).each(function () {
                    $(this).css('display', 'table-row');
                });
                break;
            default:
                $('tr.folio').each(function () {
                    $(this).css('display', 'table-row');
                });
        }
        
        var visible = false;
        $('table.folio_table tr').each(function () {
            var trClass = $(this).attr('class');
            if (!trClass) return;
            
            if (trClass.match(/folio\s/) || trClass == 'folio') {
                if ($(this).css('display') == 'table-row') {
                    visible = true;
                } else {
                    visible = false;
                }
                
                return;
            }

            if (trClass.match(/folio_space\s/) || trClass == 'folio_space') {
                if (visible) {
                    $(this).css('display', 'table-row');
                } else {
                    $(this).css('display', 'none');
                }
                return;
            }                        
        });
    });
});
