
// An array holding the news items!
newsitems = [ 
  "Lynn Elgin speaks at 29th National Symposium for Healthcare Executives^19","Katy Seto Passes LEED Exam^18","Lynn Elgin gives Keynote Address at 2009 EHS Customer Conference^17","Cathy Wright Passes LEED Exam^16","Birmingham Board of Education Publishes Strategic Plan^15","Lynn Elgin has Article Featured in Birmingham Business Journal^13","Clarus to Serve on Community Boards^3"];


// The number of seconds it stays on the text before fade in/out.
holdsecs = 4.0;

// Slowliness.  Increasing this makes it fade slower.
slowliness = 100;


current_news_index = -1;
newstext = null;


var oldonload = window.onload;
window.onload = function() {
  newstext = document.getElementById('newsfeed').lastChild;
  
  // Increase the second parameter to make it slower.
  changetext( newstext, slowliness );

  if ( null != oldonload ) {
    oldonload();
  }
}



function fadein( elm, speed, currentopacity ) {
  if ( null == currentopacity ) {
    currentopacity = 1.0;
  }
  
  set_opacity( elm, currentopacity );
  
  if ( 100 < currentopacity ) {
  
    setTimeout( function() {
      fadeout( elm, speed );
    }, holdsecs * 1000 ); // fade out after 3 secs.
    
  } else {
  
    setTimeout( function() {
      fadein( elm, speed, currentopacity + currentopacity * 2 );
    }, speed );  // Fade in some more.
    
  }
}




function fadeout( elm, speed, currentopacity ) {
  if ( null == currentopacity ) {
    currentopacity = 100.0;
  }
  
  //set_opacity( elm, currentopacity );
  set_opacity( elm, 50 );
  
  if ( 0 > currentopacity ) {
  
    changetext( elm, speed ); // Change the text to the next item.
    
  } else {
  
    setTimeout( function() {
      fadeout( elm, speed, currentopacity - currentopacity * 2 );
    }, speed );  // Fade out some more.
    
  }
}


function changetext( elm, speed ) {
  // Update the index to the next news item.
  current_news_index++;
  current_news_index = current_news_index % newsitems.length;
  
  // Set the text of the news ticker
  newsArray = newsitems[ current_news_index ].split("^")
  elm.lastChild.nodeValue = newsArray[0];
  document.getElementById("newsfeed").onclick = function() { window.open('./news.php?ID='+newsArray[1],'_self') };
  
  fadein( elm, speed );
}



// Utility function for setting the opacity of a div.
function set_opacity( elm, pct ) {
  elm.style.opacity = pct / 100.0;
	elm.style.filter = 'alpha(opacity=' + pct + ')';
}