function turnOn(o){
  if (!o.t){

    // store orginal contents as part of object
    o.t=o.title;
    o.c=o.innerHTML;

    // store tooltip build as part of the object
    o.h=o.c+'<span class="tooltip"><span class="ttbox"> '+o.title+'</span><span class="ttarrow"></span></span>';
  }
  if ($(o).css('position')=="relative"){
    o.innerHTML=o.h;
    o.title='';
  }
  $(o).find('span.tooltip').fadeIn('fast');
}

function turnOff(o){
   $(o).find('span.tooltip').fadeOut('slow');
   o.innerHTML=o.c;
   o.title=o.t;
}

// loop through all objects with a title attribute
var titles=$('acronym[title]');

// use an efficient for loop as there may be a lot to cycle through
for(var i=titles.length-1;i>-1;i--){

   // titled object must be position:relative
   $(titles[i]).addClass('tooltipParent');

   // titled object must appear in the keyboard focus
   $(titles[i]).attr('tabindex','0');

   // mouse & keyboard functions
   $(titles[i])
      .hover(function(){turnOn(this);},function(){turnOff(this);})
      .focus(function(){turnOn(this);})
      .blur(function(){turnOff(this);});
}
