// array of colors that will be applied to H1 tags.
var h5Cols = ['#ffffff', '#dddddd', '#bbbbbb', '#999999', '#777777', '#ffffff'];

// main script.
var h5Arr = [];
function h5Setup()
{
 h5Arr = document.getElementsByTagName('h5');
 for (var h = 0; h < h5Arr.length; h++)
 {
  var h5 = h5Arr[h], text = h5.firstChild.nodeValue;
  h5.removeChild(h5.firstChild);
  h5.animNodes = [];
  for (var i = 0; i < text.length; i++)
  {
   var span = document.createElement('span');
   span.appendChild(document.createTextNode(text.substring(i, i+1)));
   h5.appendChild(span);
   h5.animNodes[h5.animNodes.length] = span;
  }
  h5.animCount = 0;
  h5.animTimer = setInterval('h5Anim(' + h + ')', 50);
 }
};
function h5Anim(h)
{
 var h5 = h5Arr[h], c = h5.animCount++, noAnim = 1;
 for (var i = 0; i < h5.animNodes.length; i++)
 {
  var s = h5.animNodes[i], frac = Math.max(0, Math.min(1, (c-i)/10)),
   marg = document.all && !window.opera ? 'marginRight' : 'marginLeft';
  if (s.animDone) continue;
  noAnim = 0;
  s.style.color = h5Cols[Math.floor(frac * 0.99999 * h5Cols.length)];
  if (frac == 1)
  {
   s.style[marg] = '0';
   s.animDone = 1;
  }
  else s.style[marg] = 0.6*(1-frac) + 'em';
 }
 if (noAnim) clearInterval(h5.animTimer);
 h5.style.visibility = 'inherit';
};

if (document.documentElement)
{
 // Hide H1 elements for animation and trigger show on load.
 document.write('<style type="text/css"> h5 { visibility: hidden } </style>');
 var h5aOL = window.onload;
 window.onload = function()
 {
  if (h5aOL) h5aOL();
  h5Setup();
 }
}
