$.ajaxSetup ({ cache: false });

$(document).ready(function(){

  var filter = $('ul.filter')

  var all = $('<li/>',{'class': 'first'}).append($('<a/>',{
    'href':'/portfolio/'
    , 'text': 'All'
  }));

  $(filter).prepend(all);
  var filtered = $('a',filter).hasClass('active');
  if (filtered===false) { $('.first a',filter).addClass('active'); }
  
  $('#section-portfolio div.sample a').equalHeights();
  
  $('a',filter).click(function(e){
    e.preventDefault();
    $('#samples .wrapper').hide('slow');
    var _this = $(this);
    var url = _this.attr('href');
    $('a',filter).removeClass('active').removeClass('loading');
    _this.addClass('loading').addClass('active');
    $('#samples').load(url+' #samples>.wrapper', function(){
      $('div.sample a').equalHeights();
      $(this).show('slow');
      _this.removeClass('loading');
    });
  });
});

(function($) {
  $.fn.equalHeights = function() {
    var h = 0;
    $(this).each(function(){
      h = ($(this).height()>h) ? $(this).height() : h;
    });
    $(this).each(function(){
      $(this).height(h);
    });  
  }
})(jQuery);


