/*
Created by: Dunstan Orchard :: http://1976design.com/ */
function extractImageTitles() 	{
 	images = document.getElementsByTagName('img');
	 for (var i = 0; i < images.length; i++) {
		  var title = images[i].getAttribute('title');
		  if ((title) && (title != '')) {
			   if (title.match('http://', 'i')) {
    				newlink = document.createElement('a');
    				newlink.setAttribute('href', title);
    				newlink.setAttribute('title', ('Go to ' + title));
    				newlink.appendChild(document.createTextNode('Image source'));
    				var newdiv = document.createElement('div');
    				newdiv.className = 'caption';
    				newdiv.appendChild(newlink);
    				images[i].parentNode.appendChild(newdiv);
    				images[i].removeAttribute('title');
				  } else {
    				var newdiv = document.createElement('div');
    				newdiv.className = 'caption';
    				newdiv.appendChild(document.createTextNode(title));
    				images[i].parentNode.appendChild(newdiv);
    				images[i].removeAttribute('title');
  				}
		 	}
 	}
}
// Created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
// addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
addLoadEvent(function(e) {
  extractImageTitles();
});
