var origred=255, origgreen=0, origblue=0;
var red=origred, green=origgreen, blue=origblue;
var increment=32, timedelay=500;

function colortoblack(onediv)
{
red -= increment;
green -= increment;
blue -= increment;
if (red < 0) red = 0;
if (green < 0) green = 0;
if (blue < 0) blue = 0;
if (red == 0 && (green == 0 && blue == 0))
  {
  setTimeout('colortoorig("' + onediv + '")', 1500);
  }
else
  {
  document.getElementById(onediv).style.color=rgb(red, green, blue);
  setTimeout('colortoblack("' + onediv + '")', timedelay);
  }
}

function colortoorig(onediv)
{
red += increment;
green += increment;
blue += increment;
if (red > origred) red = origred;
if (green > origgreen) green = origgreen;
if (blue > origblue) blue = origblue;
if (red == origred && (green == origgreen && blue == origblue))
  {
  setTimeout('colortoblack("' + onediv + '")', 1500);
  }
else
  {
  document.getElementById(onediv).style.color=rgb(red, green, blue);
  setTimeout('colortoorig("' + onediv + '")', timedelay);
  }
}

var colorincrement=8;

function fadeto(divid, colorto)
{
var onediv = document.getElementById(divid);
var colorfrom = onediv.style.color + '';
if (colorfrom == 'undefined') colorfrom='';
else if (colorfrom.indexOf('rgb') == 0)
  {
  colorfrom = colorfrom.substr(colorfrom.indexOf('(') + 1);
  colorfrom = colorfrom.substr(0, colorfrom.indexOf(')'));
  colorfrom = colorfrom.split(', ');
  colorfrom=rgb(colorfrom[0], colorfrom[1], colorfrom[2]);
  }
if (colorfrom.length==0) colorfrom ='#000000';

if (colorfrom.indexOf('#') == 0) colorfrom = colorfrom.substr(1);

var redfrom = parseInt('0x' + colorfrom.substr(0,2), 16);
var greenfrom = parseInt('0x' + colorfrom.substr(2,2), 16);
var bluefrom = parseInt('0x' + colorfrom.substr(4,2), 16);

if (colorto.indexOf('#') == 0) colorto=colorto.substr(1);

var redto = parseInt('0x' + colorto.substr(0,2), 16);
var greento = parseInt('0x' + colorto.substr(2,2), 16);
var blueto = parseInt('0x' + colorto.substr(4,2), 16);

var reddirection = 1, greendirection = 1, bluedirection = 1;

if (redto < redfrom) reddirection = -1;
if (greento < greenfrom) greendirection = -1;
if (blueto < bluefrom) bluedirection = -1;

if (Math.abs(redto - redfrom) <= colorincrement)
  {redfrom=redto;}
else
  {redfrom += reddirection * colorincrement;}
  
if (Math.abs(greento - greenfrom) <= colorincrement)
  {greenfrom=greento;}
else
  {greenfrom += greendirection * colorincrement;}
  
if (Math.abs(blueto - bluefrom) <= colorincrement)
  {bluefrom=blueto;}
else
  {bluefrom += bluedirection * colorincrement;}

onediv.style.color=rgb(redfrom, greenfrom, bluefrom);;

var timeout = 50;
if (redfrom == redto && (greenfrom==greento && bluefrom == blueto))
  {
  ti++;
  ti %= titlecolor.length;
  colorto=titlecolor[ti];
  timeout=1200;
  }
setTimeout('fadeto("' + divid + '", "' + colorto + '")', timeout);
}

function rgb(red, green, blue)
{
var rgbcolor='#';
var hexdigit='0123456789abcdef';

rgbcolor += hexdigit.charAt(Math.floor(red / 16));
rgbcolor += hexdigit.charAt(red % 16);
rgbcolor += hexdigit.charAt(Math.floor(green / 16));
rgbcolor += hexdigit.charAt(green % 16);
rgbcolor += hexdigit.charAt(Math.floor(blue / 16));
rgbcolor += hexdigit.charAt(blue % 16);

return rgbcolor;
}

function switchpic(src, img)
{
document.getElementById(img).src = src;
//document.images[img].src=src;
}

var spanindex=0, ti=0, interval=250, spanmax=6;
var titlecolor=['#ff0000', '#0000bb', '#ff8833', '#000000', '#00aa00'];
var titlespan=new Array();

for (var si=0;si<spanmax;si++)
  {
  titlespan[si]=null;
  }

function changecolor()
{
if (titlespan[spanindex]==null)
  {
  titlespan[spanindex]=document.getElementById('bigsky' + spanindex);
  }
titlespan[spanindex].style.color=titlecolor[ti];
spanindex++;
spanindex %= spanmax;
if (spanindex==0)
  {
  ti++;
  ti %= titlecolor.length;
  }
setTimeout('changecolor()', interval);
}

setTimeout('fadeto("bigskytitle", "' + titlecolor[0] + '")', 3000);
//setTimeout('fadeto("bigskymini", "' + titlecolor[0] + '")', 3000);
