/// JQuery Tabs Plugin
/// Usage:
///   $('div.tabs ul').tabs({ before : function() {}, after : function() {}});
///   $('div.tabs ul').tabs(function() {}); 
(function($) {

  $.fn.tabs = function(options) {

    var links = this.find('li a');

    var options = {
      before : options &&
               ((typeof options == 'function' && options) ||
                (typeof options == 'object' && options.before)),
      after  : options && (typeof options == 'object') && 
               options.after };

    links.each(function (current) {
      $(this).data('tab', { 
        index  : current, 
        target : this.href.substr(this.href.indexOf('#')) });

      $(this).click(function () {
        options.before && options.before(this);

        links.
          removeClass('active').
          each(function (index) { $($(this).data('tab').target).hide(); });
        
        $(this).addClass('active');
        $($(this).data('tab').target).show();
        
        options.after && options.after(this);

        return false;
      });
    });
    return this;
  }
})(jQuery);