/* -- Fading Content Rotator  ------------------------------ */

var delay = 8000; //set delay between message change (in miliseconds)
var maxsteps=30; // number of steps to take to change from hidden to fully visible
var stepdelay=40; // time in miliseconds of a single step
//**Note: maxsteps*stepdelay will be total time in miliseconds of fading effect

var dbi=0;

var whatsHotContent=new Array();


///No need to edit below this line/////////////////


var ie4=document.all&&!document.getElementById;
var DOM2=document.getElementById;

var moz	  = ( document.getElementById && !document.all );


function getObject( objID ) { //-generic object retrieval function to cater for different dom implementations
	if ( document.all && !document.getElementById ) return document.all.item( objID );
	else if ( document.getElementById ) return document.getElementById( objID );	
}



var faderdelay=0;
var index=0;
var mozchangeWhatsHotContent = 0; //--exist to resolve a bug with mozilla rendering opacity, in that it seems to keep a previous opacity and re-use it when the innerHTML is changed ( or something similar )


function initWhatsHotRotator( ) {

  //--Extract content for The Latest area from the storage block
  //--whatsHotContent[] is used by file :: whatsHot_rotator.js
	var tlEls = document.getElementById("whatsHotStorage").getElementsByTagName("SPAN");    
	for (var i=0; i<tlEls.length; i++) {
    whatsHotContent[i] = tlEls.item(i).innerHTML;
  }
  
  changeWhatsHotContent();
}

/*Rafael Raposo edited function*/
//function to change content
function changeWhatsHotContent(){
  mozchangeWhatsHotContent = 2; //--rendering the content twice resolves the mozilla opacity bug
  
  if (DOM2){

    if( moz )      
      document.getElementById("fadingRotatorContainer").style.MozOpacity = 0;
    else {
      document.getElementById("fadingRotatorContainer").filters.alpha.opacity = 0;
      document.getElementById("fadingRotatorContainer").innerHTML=whatsHotContent[index];
    }
    
    contentFade( 1 );
  } else if( ie4 ) document.all.fadingRotatorContainer.innerHTML = whatsHotContent[index];
  
  if ( ++index>=whatsHotContent.length ) index=0;
}

//--------------------------------------
var fadecounter;
function contentFade( step ) {
  if( step<=maxsteps ) {	

    if( moz ) {
      document.getElementById("fadingRotatorContainer").style.MozOpacity = step / maxsteps;
      if( mozchangeWhatsHotContent-- > 0 ) { document.getElementById("fadingRotatorContainer").innerHTML=whatsHotContent[index]; } //--this is here for moz [ instead of in changeWhatsHotContent( ) ] due to a display error with oapacity
    } else 
      document.getElementById("fadingRotatorContainer").filters.alpha.opacity = step / maxsteps * 100;
      

    step++;
    fadecounter=setTimeout("contentFade("+step+")", stepdelay);
  } else {
    clearTimeout( fadecounter );
    if( moz )      
      document.getElementById("fadingRotatorContainer").style.MozOpacity = 1; else
      document.getElementById( "fadingRotatorContainer" ).filters.alpha.opacity = 100;
    if( whatsHotContent.length > 1 ) setTimeout( "changeWhatsHotContent( )", delay );
	
  }   
}


//if (window.addEventListener) window.addEventListener("load", changeWhatsHotContent, false);
//else if (window.attachEvent) window.attachEvent("onload", changeWhatsHotContent);
//else if (document.getElementById) window.onload=changeWhatsHotContent;


if (window.addEventListener) window.addEventListener("load", initWhatsHotRotator, false);
else if (window.attachEvent) window.attachEvent("onload", initWhatsHotRotator);
else if (document.getElementById) window.onload=initWhatsHotRotator;

