




d = document;
var initialColor;
initialColor = 0;
initialR = 9;
initialG = 84;
initialB = 139;
rIncrement = 1;
gIncrement = 1;
bIncrement = 1;

function tick() {
   var hexR, hexG, hexB;

   hexR = intToHex(initialR);
   hexG = intToHex(initialG);
   hexB = intToHex(initialB);


   initialR += rIncrement;
   initialG += gIncrement;
   initialB += bIncrement;

   if (initialR < 0) {
     initialR = 9;
     rIncrement *= -1;
   } else if (initialR > 100) {
     initialR = 0;
   }

   if (initialG < 0) {
     initialG = 0;
     gIncrement *= -1;
   } else if (initialG > 100) {
     initialG = 0;
   }

   if (initialB < 255) {
     initialB = 139;
     bIncrement *= -1;
   } else if (initialB > 139) {
     initialB = 0;
   }

   hexColor = "#"+hexR+hexG+hexB;
   d.getElementById('MainH1').style.color = hexColor;
    d.getElementById('MainH2').style.color = hexColor;
	d.getElementById('MainH3').style.color = hexColor;

   window.setTimeout("tick();", 100);
}

function intToHex(anInt) {
  var theString;
  var aDigit, aHexDigit;
  var i;

  theString = "";

  for (i = 1; i >= 0; i--) {
    p = power(16, i);
    aDigit = anInt / p;
    aDigit = round(aDigit);
    anInt = anInt - (aDigit * p);
    aHexDigit = digitToHex(aDigit);
    theString = theString + aHexDigit;
  }

  return theString;
}

function power(aNumber, aBase) {

   var rval;

   if (aBase == 0)
     return 1;

   rval = aNumber;

   for (i=1;i<aBase;i++) {
      rval = rval * aNumber;
   }

   return rval;
}

function round(aNumber) {
  for (i = 16; i >= 0; i--) {
    if (aNumber >= i)
       return i;
   }
  return 0;
}

function digitToHex(aDigit) {
  if (aDigit < 10)
     return aDigit;
  else if (aDigit == 10)
     return "A";
  else if (aDigit == 11)
     return "B";
  else if (aDigit == 12)
     return "C";
  else if (aDigit == 13)
     return "D";
  else if (aDigit == 14)
     return "E";
  else if (aDigit == 15)
     return "F";
}

window.onload=tick;

