Drupal.TMA = function(target) {
  var b = this;
  
  this.nid = $(target).attr("id");
  this.nodeLeft = '#' + this.nid + ' div.ex-left'; 
  this.nodepdf = '#' + this.nid + ' div.ex-left' + ' div.section-pdfs'; 
  this.nodeRight = '#' + this.nid + ' div.ex-right';
  this.more = this.nodeRight + ' a.more';  
  this.less = this.nodeRight + ' a.less'; 
  this.opened = false; 
  
  $(this.nodeLeft +' a:gt(0)').hide();
  $(this.nodeRight +' p:gt(0)').hide();
  $(this.nodeRight +' p:gt(0) strong').hide();
    $(this.nodeRight +' form').hide();
    $(this.nodeRight +' form p img').hide();
    $(this.nodeRight +' form select').hide();
  $(this.nodepdf).hide();
  
  var count = 0;
  $(this.nodeRight +' p').each(function() {
    count++;
  });
  
  if (count > 1) { $(this.nodeRight+' div.ex-right-content').append('<a class="more" href="#" rel="' + this.nid + '">read more &raquo;</a>'); }
  
  $(this.more).click(function () {
    b.Toggle();
    return false;
  });
}

Drupal.TMA.prototype.ShowExtra = function() {
  var b = this;
  this.opened = true;
  $(this.nodeLeft +' a:gt(0)').slideDown();
  $(this.nodeRight +' p:gt(0)').slideDown();
  $(this.nodeRight +' p:gt(0) strong').slideDown();
    $(this.nodeRight +' form').slideDown();
    $(this.nodeRight +' form p img').slideDown();
    $(this.nodeRight +' form select').slideDown();
  $(this.nodepdf).slideDown();
  $(this.more).html('&laquo; show less');
}

Drupal.TMA.prototype.HideExtra = function() {
  var b = this;
  this.opened = false;
  $(this.nodeLeft +' a:gt(0)').slideUp();
  $(this.nodeRight +' p:gt(0)').slideUp();
  $(this.nodeRight +' p:gt(0) strong').slideUp();
    $(this.nodeRight +' form').slideUp();
    $(this.nodeRight +' form p img').slideUp();
    $(this.nodeRight +' form select').slideUp();
  $(this.nodepdf).slideUp();
  $(this.more).html('read more &raquo;');
}

Drupal.TMA.prototype.Toggle = function() {
  if ( this.opened ) this.HideExtra();
  else this.ShowExtra();
}

Drupal.behaviors.TMA_attach = function (context) {
  $('div.view-content div.node').each(function() {
    new Drupal.TMA(this);
  });
};
