﻿<!--
var initialColor;
initialColor = 0;
initialR = 254;
initialG = 2;
initialB = 128;
rIncrement = -1;
gIncrement = 1;
bIncrement = -1;

function tick() {
   var hexR, hexG, hexB;

   hexR = intToHex(initialR);
//alert(hexR);
   hexG = intToHex(initialG);
//alert(hexG);
   hexB = intToHex(initialB);
//alert(hexB);

   initialR += rIncrement;
   initialG += gIncrement;
   initialB += bIncrement;

   if (initialR < 0) {
     initialR = 255;
     rIncrement *= -1;
   } else if (initialR > 255) {
     initialR = 0;
   }

   if (initialG < 0) {
     initialG = 255;
     gIncrement *= -1;
   } else if (initialG > 255) {
     initialG = 0;
   }

   if (initialB < 0) {
     initialB = 255;
     bIncrement *= -1;
   } else if (initialB > 255) {
     initialB = 0;
   }
    
   hexColor = "#"+hexR+hexG+hexB;
   MainH1.style.color = hexColor;

   window.setTimeout("tick();", 10);
}

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;
// -->