var colorFadeArray = new Array;
var colorStep = 0;
var numSteps = 0;
var fadeClassTimeout;

/***********************************************
*
* Function : getColor
*
* Parameters : start - the start color (in the form "RRGGBB" e.g. "FF00AC")
* end - the end color (in the form "RRGGBB" e.g. "FF00AC")
* percent - the percent (0-100) of the fade between start & end
*
* returns : color in the form "#RRGGBB" e.g. "#FA13CE"
*
* Description : This is a utility function. Given a start and end color and
* a percentage fade it returns a color in between the 2 colors
*
* Author : Open Source
*
*************************************************/
function getColor(start, end, percent)
{
function hex2dec(hex){return(parseInt(hex,16));}
function dec2hex(dec){return (dec < 16 ? "0" : "") + dec.toString(16);}

var r1=hex2dec(start.slice(0,2));
var g1=hex2dec(start.slice(2,4));
var b1=hex2dec(start.slice(4,6));

var r2=hex2dec(end.slice(0,2));
var g2=hex2dec(end.slice(2,4));
var b2=hex2dec(end.slice(4,6));

var pc = percent/100;

var r= Math.floor(r1+(pc*(r2-r1)) + .5);
var g= Math.floor(g1+(pc*(g2-g1)) + .5);
var b= Math.floor(b1+(pc*(b2-b1)) + .5);

return("#" + dec2hex(r) + dec2hex(g) + dec2hex(b));
}
/************************************************/

function changecss(theClass,element,value) {
//documentation for this script at http://www.shawnolson.net/a/503/
 var cssRules;
 if (document.all) {
  cssRules = 'rules';
 }
 else if (document.getElementById) {
  cssRules = 'cssRules';
 }

  for (var R = 0; R < document.styleSheets[0][cssRules].length; R++) {
   if (document.styleSheets[0][cssRules][R].selectorText == theClass) {
    document.styleSheets[0][cssRules][R].style[element] = value;
   }
  }
 	
}

function doFadeClass(theClass, startColor, endColor, steps, seconds) {
//first create a color fade
   for (i = 0; i < steps; i++) {
    colorFadeArray[i] = getColor(startColor, endColor, ((i+1) * (100 / steps)));
   }
   interval = ((seconds * 1000) / steps);
   fadeClassTimer = setTimeout('fadeClassStep("'+theClass+'", '+interval+')', interval);
}

function fadeClassStep (theClass, intervak) {
   changecss('.newHospital','background',colorFadeArray[colorStep]);
   colorStep++;
   if (colorStep == colorFadeArray.length) {
      colorStep = 0;
      clearTimeout(fadeClassTimer);
   } else {
      fadeClassTimer = setTimeout('fadeClassStep("'+theClass+'", '+interval+')', interval);
   }
}
   