(function() {
  var $, emailize, out, over;

  $ = jQuery;

  over = function(e) {
    var logo_bw, logo_color;
    logo_bw = $(this).find('img').attr('src');
    logo_color = logo_bw.replace('bw', 'color');
    return $(this).find("a.client_logo").css({
      background: "url(" + logo_color + ") no-repeat center bottom"
    }).end().find("span").stop().fadeTo(200, 0, function() {
      return $(this).hide();
    });
  };

  out = function(e) {
    return $(this).find('span').stop().fadeTo(200, 1, function() {
      return $(this).parent("a.client_logo").css({
        'background-image': 'none'
      });
    });
  };

  $.fn.equalHeights = function() {
    return this.each(function() {
      var columns, img, row, tallest;
      tallest = 0;
      row = $(this);
      columns = row.children("div").not(".bottom_image");
      img = row.find(".bottom_image");
      return columns.each(function() {
        var thisHeight;
        thisHeight = $(this).outerHeight();
        if (thisHeight > img.css('min-height')) {
          return img.css({
            'min-height': thisHeight
          });
        }
      });
    });
  };

  $.fn.adjustBottomImageHeight = function() {
    return this.each(function() {
      var col, imgH, row;
      row = $(this);
      col = row.find(".bottom_image");
      imgH = col.children('img').height();
      col.css('min-height', '');
      if (col.css('float') !== 'none') {
        col.css('min-height', row.height());
        if (imgH > row.height()) return col.css('min-height', imgH);
      } else {
        return col.css('min-height', imgH);
      }
    });
  };

  $.fn.filterize = function() {
    return this.each(function() {
      return $(this).click(function() {
        var selector;
        selector = $(this).attr('data-filter');
        $('.filter a').removeClass('active');
        $('#cards').isotope({
          filter: selector
        });
        $(this).addClass('active');
        return false;
      });
    });
  };

  $.fn.email = function() {
    return this.each(function() {
      var e;
      e = emailize($(this).text());
      return $(this).attr('href', "mailto:" + e).text(e);
    });
  };

  emailize = function(name) {
    var dom;
    dom = 'interactivethings';
    return "" + (name.toLowerCase()) + "@" + dom + ".com";
  };

  $.fn.loadDatavisThumbs = function(count) {
    var req;
    if (count == null) count = 5;
    req = $.getJSON("http://datavisualization.ch/aggregator/?q=latest_posts&callback=?&count=" + count);
    return this.each(function() {
      var item;
      item = $(this);
      return req.success(function(data) {
        var post, _i, _len, _ref;
        if (data.status === 'ok') {
          _ref = data.posts;
          for (_i = 0, _len = _ref.length; _i < _len; _i++) {
            post = _ref[_i];
            item.append("<li><a href='" + post.post_url + "' title='" + post.post_title + "' target='_blank'><img src='" + post.thumb_url + "' alt='" + post.post_title + " Teaser' class='headline_align' /></a></li>");
          }
        }
        return $('#lab_datavisualization_images li a[title]').qtip({
          position: {
            my: 'bottom center',
            at: 'top center'
          },
          style: {
            classes: 'ui-tooltip-tipsy'
          },
          show: {
            effect: function() {
              return $(this).show().css({
                opacity: 0,
                marginTop: -20
              }).animate({
                opacity: 1,
                marginTop: 0
              }, 100);
            }
          }
        });
      });
    });
  };

  $.fn.addQTip = function() {
    return this.each(function() {
      return $('li a[title]', this).qtip({
        position: {
          my: 'bottom center',
          at: 'top center'
        },
        style: {
          classes: 'ui-tooltip-tipsy ui-tooltip-tipsy-light'
        },
        show: {
          effect: function() {
            return $(this).show().css({
              opacity: 0,
              marginTop: -20
            }).animate({
              opacity: 1,
              marginTop: 0
            }, 100);
          }
        }
      });
    });
  };

  $.fn.propagateClass = function() {
    return this.each(function() {
      return $('li a', this).hover(function() {
        return $(this).closest('.slide').attr({
          id: 'spotlight_' + $(this).attr("id")
        });
      });
    });
  };

  $(function() {
    $('.team .person .row, .team #overview .row').adjustBottomImageHeight();
    $(window).resize(function() {
      return $('.team .person .row, .team #overview .row').adjustBottomImageHeight();
    });
    $('.home .showcase, .project .showcase').showcase({
      timerIsOn: false
    });
    $('.work .showcase').showcase({
      timerIsOn: false
    });
    $('.lab .showcase').showcase({
      timerIsOn: true
    });
    $('.works .slide, #deck, .card, .teaser').bind('mouseover mouseout', function() {
      return $(this).toggleClass('hovered');
    });
    $('.client').hover(over, out);
    $('.flipbook').showcase();
    $('.teaser').fitted();
    $('.card').fitted();
    $('a.email').email();
    $('#lab_datavisualization_images').loadDatavisThumbs(4);
    $('#lab_substratum_images').addQTip();
    $('#lab_substratum_images').propagateClass();
    $('#lab_sxsw2012_images').addQTip();
    $('#cards').isotope({
      itemSelector: '.card',
      layoutMode: 'cellsByRow',
      cellsByRow: {
        columnWidth: 380,
        rowHeight: 352
      }
    });
    return $('.filter a').filterize();
  });

}).call(this);

