var prevSelected = '';
function check(obj)
{
$('.filter_text .selected').removeClass('selected');
$('a.checkbox').each(function(){
    $(this).removeClass('active');
    $(this).next().removeAttr('checked');
});

    if(prevSelected != $(obj).attr('rel'))
    {
        $('.filter_text a[rel='+$(obj).attr('rel')+']').addClass('selected');


        if($(obj).attr('rel') == 'new')
        {
            $('a.checkbox[rel=new]').each(function(){
                $(this).addClass('active');
                $(this).next().attr('checked','checked');
            });
        }
        else if($(obj).attr('rel') == 'old')
        {
            $('a.checkbox[rel=old]').each(function(){
                $(this).addClass('active');
                $(this).next().attr('checked','checked');
            });
        }
        else if($(obj).attr('rel') == 'all')
        {
            $('a.checkbox').each(function(){
                $(this).addClass('active');
                $(this).next().attr('checked','checked');
            });
        }
        prevSelected = $(obj).attr('rel');
    }
    else
    {
        if($(obj).attr('rel') == 'new')
        {
            $('a.checkbox[rel=new]').each(function(){
                $(this).removeClass('active');
                $(this).next().removeAttr('checked');
            });
        }
        else if($(obj).attr('rel') == 'old')
        {
            $('a.checkbox[rel=old]').each(function(){
                $(this).removeClass('active');
                $(this).next().removeAttr('checked');
            });
        }
        else if($(obj).attr('rel') == 'all')
        {
            $('a.checkbox').each(function(){
                $(this).removeClass('active');
                $(this).next().removeAttr('checked');
            });
        }
        prevSelected = '';
    }
}


var previousCheckbox;
$('a.checkbox').live('click', function(e){
    e.preventDefault();
    $(this).toggleClass('active').next().click();
    if (e.shiftKey && previousCheckbox != 'undefined' && previousCheckbox != $(this).get(0)) {
        var click = [];
        var current = $(this).get(0);
        var isActive = $(this).hasClass('active');
        $('a.checkbox').each(function(){
            var get = $(this).get(0);
            if (get == current || get == previousCheckbox) {
                if (click.length) {
                    //click.shift();
                    $.each(click, function(){
                        if (this.hasClass('active') && ! isActive || ! this.hasClass('active') && isActive) {
                            this.toggleClass('active').next().click();
                        }
                    });
                    return false;
                } else click.push($(this));
            } else if (click.length) {
                click.push($(this));
            }
        });
    } else {
        previousCheckbox = $(this).get(0);
    }
});


