var fadeDelay = 5; // ms
var red = 255;
var green = 255;
var blue = 255;
var lighterRed = 80;
var lighterGreen = 43;
var lighterBlue = 40;

// ****************************************************************************
// reset the fade colors to default
// ****************************************************************************
function resetDarkFade(){
  red = 255;
  green = 255;
  blue = 255;
}

// ****************************************************************************
// this will fade normal text in from white to target colors
// ****************************************************************************
function fadeTextDarker(){
  var targetRed = 63;
  var targetGreen = 0;
  var targetBlue = 0;

  // set span id = fade text color
  document.getElementById("content").style.color="rgb(" + red + "," + green + "," + blue + ")";

  // subtract to get closer to the target color of #224444
  if (red > targetRed){
    red -= 10;
    if (red < targetRed) red = targetRed;       // make sure not less than target
  }
  if (green > targetGreen){
    green -= 10;
    if (green < targetGreen) green = targetGreen;   // make sure not less than target
  }
  if (blue > targetBlue){
    blue -= 10;
    if (blue < targetBlue) blue = targetBlue;     // make sure not less than target
  }

  // if still needing to adjust a color, then loop again
  if(red > targetRed || green > targetGreen || blue > targetBlue) {
    setTimeout('fadeTextDarker();', fadeDelay); // delay
  }
}

// ****************************************************************************
// reset the fade colors to default
// ****************************************************************************
function resetLightFade(){
  lighterRed = 80;
  lighterGreen = 43;
  lighterBlue = 40;
}

// ****************************************************************************
// this will fade normal text in from white to target colors
// ****************************************************************************
function fadeTextLighter(){
  var targetRed = 255;
  var targetGreen = 255;
  var targetBlue = 255;

  // set span id = fade text color
  document.getElementById("infoContent").style.color="rgb(" + lighterRed + "," + lighterRed + "," + lighterRed + ")";

  // subtract to get closer to the target color of #224444
  if (lighterRed < targetRed){
    lighterRed += 10;
    if (lighterRed > targetRed) lighterRed = targetRed;       // make sure not less than target
  }
  if (lighterGreen < targetGreen){
    lighterGreen += 10;
    if (lighterGreen > targetGreen) lighterGreen = targetGreen;   // make sure not less than target
  }
  if (lighterBlue < targetBlue){
    lighterBlue += 10;
    if (lighterBlue > targetBlue) lighterBlue = targetBlue;     // make sure not less than target
  }

  // if still needing to adjust a color, then loop again
  if(lighterRed < targetRed || lighterGreen < targetGreen || lighterBlue < targetBlue) {
    setTimeout('fadeTextLighter();', fadeDelay); // delay
  }
}

// ****************************************************************************
// this will fade normal text in from white to target colors
// ****************************************************************************
function fadeAbstractLighter(){
  var targetRed = 255;
  var targetGreen = 255;
  var targetBlue = 255;    // set span id = fade text color
  document.getElementById("infoAbtract").style.color="rgb(" + lighterRed + "," + lighterRed + "," + lighterRed + ")";

  // subtract to get closer to the target color of #224444
  if (lighterRed < targetRed){
    lighterRed += 10;
    if (lighterRed > targetRed) lighterRed = targetRed;       // make sure not less than target
  }
  if (lighterGreen < targetGreen){
    lighterGreen += 10;
    if (lighterGreen > targetGreen) lighterGreen = targetGreen;   // make sure not less than target
  }
  if (lighterBlue < targetBlue){
    lighterBlue += 10;
    if (lighterBlue > targetBlue) lighterBlue = targetBlue;     // make sure not less than target
  }

  // if still needing to adjust a color, then loop again
  if(lighterRed < targetRed || lighterGreen < targetGreen || lighterBlue < targetBlue) {
    setTimeout('fadeAbstractLighter();', fadeDelay); // delay
  }
}

// ****************************************************************************
// this will fade normal text in from white to target colors
// ****************************************************************************
function toggleAbstract(target){

  // we can get by id
  if (document.getElementById){
    // show the abstract, hide the summary
    if (target == 'show'){
      // hide these
      document.getElementById('infoContent').style.display='none';
      document.getElementById('infoImage').style.display='none';
      document.getElementById('infoAbstractLink').style.display='none';
      // show these
      document.getElementById('infoAbtract').style.display='block';
      document.getElementById('infoSummaryLink').style.display='inline';
      // now fade the transition
      resetLightFade();
      fadeAbstractLighter();
    }
    // show the summary, hide the abstract
    else if (target == 'hide'){
      // hide these
      document.getElementById('infoAbtract').style.display='none';
      document.getElementById('infoSummaryLink').style.display='none';
      // show these
      document.getElementById('infoContent').style.display='block';
      document.getElementById('infoImage').style.display='block';
      document.getElementById('infoAbstractLink').style.display='inline';
      // now fade the transition
      resetLightFade();
      fadeTextLighter();
    }
  }
}
