/**
 * (c) 2004-2008 Angus Turnbull http://www.twinhelix.com
 */

// An array of colours that will be applied to H1 tags.
var h1Cols = ['#000000', '#DDDDDD', '#BBBBBB', '#999999', '#777777', '#555555'];
// velocity feed
var v_f = 50;
// starting marging feed
var m_f = 0.2;

// Main script.
var h1Arr = [];
function h1Setup()
{
 h1Arr = document.getElementsByTagName('h1');
 for (var h = 0; h < h1Arr.length; h++)
 {
  var h1 = h1Arr[h], text = h1.firstChild.nodeValue;
  h1.removeChild(h1.firstChild);
  h1.animNodes = [];
  for (var i = 0; i < text.length; i++)
  {
   var span = document.createElement('span');
   span.appendChild(document.createTextNode(text.substring(i, i+1)));
   h1.appendChild(span);
   h1.animNodes[h1.animNodes.length] = span;
  }
  h1.animCount = 0;
  h1.animTimer = setInterval('h1Anim(' + h + ')', v_f);
 }
};
function h1Anim(h)
{
 var h1 = h1Arr[h], c = h1.animCount++, noAnim = 1;
 for (var i = 0; i < h1.animNodes.length; i++)
 {
  var s = h1.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 = h1Cols[Math.floor(frac * 0.99999 * h1Cols.length)];
  if (frac == 1)
  {
   s.style[marg] = '0';
   s.animDone = 1;
  }
  else s.style[marg] = m_f*(1-frac) + 'em';
 }
 if (noAnim) clearInterval(h1.animTimer);
 h1.style.visibility = 'inherit';
};

if (document.documentElement)
{
 // Hide H1 elements for animation and trigger show on load.
 document.write('<style type="text/css"> h1 { visibility: hidden } </style>');
 var h1aOL = window.onload;
 window.onload = function()
 {
  if (h1aOL) h1aOL();
  h1Setup();
 }
}

