$.fn.extend({
  any: function() {
    return this.length > 0;
  },
  
  none: function() {
    return this.length == 0;
  }
})

var app = {
  init: function() {
    this.tabs.init();
    this.sortable.init();
    this.columns.init();
  },
  
  tabs: {
    init: function() {
      $('#tabs').tabs({
        show: function(event, ui) {
          app.scales.refresh();
          app.columns.resize();
        }
      });
    }
  },
  
  scales: {
    refresh: function() {
      $('.date:empty').parents('.scale:visible').children('a.show').each(function(index, anchor) {
        jQuery.get(anchor.href, null, null, 'script');
      });
    }
  },
  
  scalings: {
    refresh: function() {
      new_scalings = $('.content').parents('.scaling:visible');
      new_scalings.find('.content').css("background", "url(/images/ajax-loader.gif) center no-repeat");
      new_scalings.find('a.show').each(function(index, anchor) {
        data = { date: new_scalings.parents('.scale').find('.date').data('date').toDateString() }
        jQuery.get(anchor.href, data, function() {
          $(anchor).parents('.scaling').find('.content').css("background", "none");
        }, 'script');
      });
    }
  },

  sortable: {
    init: function() {
    }
  },
  
  columns: {
    init: function() {
      $(window).resize(this.resize);
    },
    
    resize: function() {
      $('.column:visible').each(function(index, element) {
        $(element).css({'height': ($(window).height() - element.offsetTop - 10)+'px'})
      });
    }
  }
};

$(function() {
  app.init();
})



