// ==UserScript==
// @name        Image Alt to Title Attributes
// @namespace   http://www.scss.com.au/family/andrew/opera/userjs/
// @version     1.2
// @date        2008-12-15
// @author      Andrew Gregory <andrew at scss dot com dot au>
// @description Copies image alt attributes to the title (for tooltips).
// @include     *
// ==/UserScript==
// License:     http://creativecommons.org/licenses/by-nc-sa/2.0/
// Notes:       Does not replace an existing title attribute. If the image
//              doesn't have alt text, it is given a single character (an 'X' in
//              a circle).
document.addEventListener('load', function() {
  var a, e, i, imgs, fix = function(img, alt) {
    if (img.hasAttribute('alt')) {
      if (!img.hasAttribute('title')) {
        img.setAttribute('title', img.getAttribute('alt'));
      }
    } else {
      img.setAttribute('alt', alt);
    }
  };
  e = document.createElement('span');
  e.innerHTML = '&otimes;';
  a = e.firstChild.nodeValue;
  imgs = document.getElementsByTagName('img');
  for (i = 0; i < imgs.length; i++) fix(imgs[i], a);
  imgs = document.getElementsByTagName('input');
  for (i = 0; i < imgs.length; i++) {
    if (imgs[i].hasAttribute('type') && imgs[i].getAttribute('type').toLowerCase() == 'image') fix(imgs[i], a);
  }
}, false);
