﻿function setRotator(container, timeout) 
{

    var hyperlinks = document.getElementById(container).getElementsByTagName("LI");

    var currentIndex =-1;
    var newIndex = -1;
    var millisec = 1500;
    for (itemCount=0 ; itemCount < hyperlinks.length ; itemCount++)
    {
        node = hyperlinks[itemCount];
        
       if (node.style.opacity > 0.5)
      {
          currentIndex = itemCount;
          opacity(node.id, 100, 0, millisec);
         }
       else
        {
            node.style.opacity = 0; 
            node.style.MozOpacity = 0; 
            node.style.KhtmlOpacity = 0; 
            node.style.filter = "alpha(opacity=0)";
 
        }
    } 
    newIndex = parseInt(Math.random()* hyperlinks.length); 
    
    while (newIndex == currentIndex &&  hyperlinks.length >1) {
        newIndex =parseInt(Math.random()* hyperlinks.length); 
    }
    node = hyperlinks[newIndex];
    opacity(node.id, 0, 100, millisec);
   // setTimeout("opacity('"+node.id+"', 0, 100, '"+millisec+"')", 100);         
    timer = setTimeout("setRotator('" + container + "'," + timeout +")", timeout);
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) {
            if (i == 0)
                break; 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) { 
            if (i == 100)
                break;
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 
                
//change the opacity for different browsers 
function changeOpac(opacityValue, id) { 

    var object = document.getElementById(id).style;
    if (opacityValue < 2 )
    {
        object.visibility = "hidden";
    }
    else if (opacityValue >= 2 )
    {
        object.visibility = "visible";
    } 
    object.opacity = (opacityValue / 100); 
    object.MozOpacity = (opacityValue / 100); 
    object.KhtmlOpacity = (opacityValue / 100); 
    object.filter = "alpha(opacity=" + opacityValue + ")";
     
}