Drupal.TMAVocab = function(target) {
  var b = this;
  
  this.vocab = '#' + $(target).attr("id");
  this.vocab = this.vocab.replace('&', '\\&');
  this.more = this.vocab + ' a.more';  
  this.less = this.vocab + ' a.less'; 
  this.opened = false; 
  
  $(this.vocab +' p:gt(0)').hide();
  var i = 0;
  $(this.vocab +' p:gt(0)').each(function() { i++; });
  if (i) { $(this.vocab).append('<a class="more" href="#" >read more &raquo;</a>'); }
  
  $(this.more).click(function () {
    b.Toggle();
    return false;
  });
}

Drupal.TMAVocab.prototype.ShowExtra = function() {
  var b = this;
  this.opened = true;
  $(this.vocab +' p:gt(0)').slideDown();
  $(this.more).html('&laquo; show less');
}

Drupal.TMAVocab.prototype.HideExtra = function() {
  var b = this;
  this.opened = false;
  $(this.vocab +' p:gt(0)').slideUp();
  $(this.more).html('read more &raquo;');
}

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

Drupal.behaviors.TMA_vocab = function (context) {
  $('div.content div#front-information div.tma-vocab').each(function() {
    new Drupal.TMAVocab(this);
  });
};
