(function($){
    $.fn.extend({
        radio:function(name){
            checkboxes = this;
            return this.bind('click.radio',function(){
                checkboxes.removeClass(name);
                $(this).addClass(name);
                return false;
            });
        }
    });
})(jQuery);

function reloadPortfolio(){
    var checked = jQuery('.checked').attr('id');
    if(checked == 'all'){
        jQuery('.client').slideDown({queue:'global',scope:'list',duration:325});
    }else{
        jQuery('.client').each(function(){
            if($(this).hasClass(checked) == true){
                $(this).slideDown({queue:'global',scope:'list',duration:325});
            }else{
                $(this).slideUp({queue:'global',scope:'list',duration:325});
            }
        });
    }
}

function checkQueue(){
    if($.fxqueue('global').getScope('list') != false){
        return false;
    }
    if($.fxqueue('global').getScope('slide') != false){
        return false;
    }
    return true;
}

jQuery(function($){
    $('.client').animate({height:'show'},{queue:'global',scope:'list'});
    $('.client').animate({height:'show'},{queue:'global',scope:'slide'});
    $('.checkbox').click(function(){
        if(checkQueue() == true){
            $('.checked').removeClass('checked');
            $(this).addClass('checked');
            $('.client .hide:visible').each(function(){
                $(this).click();
            });
            reloadPortfolio();
        }
    });

    $('.show, .thumbnail').click(function(){
        if(checkQueue() == true){
            var client = $(this).parents('div.client');
            $('.client').not(client).slideUp({queue:'global',scope:'list',duration:325});
            $('.thumbnail',client).fadeOut({queue:'global',scope:'list',duration:325})
                .siblings('.preview').animate({width:'show',height:'show'},{queue:'global',scope:'slide',duration:300})
                .siblings('.info').animate({width:'480px'},{queue:'global',scope:'slide',duration:300})
                .children('.body').css('min-height','66px')
                .children('ul').fadeOut({queue:'global',duration:300})
                .children('.show').hide({queue:'global',scope:'change',duration:1})
                .siblings('.desc, .link, .hide').show({queue:'global',scope:'change',duration:1})
                .parents('ul').slideDown({queue:'global',duration:300})
                .parents('.body').css('min-height','auto');
            return false;
        }
    });

    $('.hide').click(function(){
        if(checkQueue() == true){
            var client = $(this).parents('div.client');
            $('.body',client).css('min-height','66px')
                .children('ul').slideUp({queue:'global',duration:300})
                .children('.desc, .link, .hide').hide({queue:'global',scope:'change',duration:1})
                .siblings('.show').show({queue:'global',scope:'change',duration:1})
                .parents('ul').fadeIn({queue:'global',duration:300})
                .parents('.body').css('min-height','auto')
                .parents('.info').animate({width:'650px'},{queue:'global',scope:'slide',duration:300})
                .siblings('.preview').animate({width:'hide',height:'hide'},{queue:'global',scope:'slide',duration:300})
                .siblings('.thumbnail').fadeIn({queue:'global',scope:'list',duration:325});
            reloadPortfolio();
            return false;
        }
    });
});