﻿//<!--

function rotate(ctlidprefix, currentindexctl, move, firstindex, lastindex, autorotatectlid, autorotateaction, autorotateinterval) 
{
   // autorotateaction: -1 = turn off; 0 = do nothing; 1 = turn on;
   try
   {    

      // verify numeric parameters
      if (!isNaN(move) && !isNaN(firstindex) && !isNaN(lastindex) && !isNaN($$(currentindexctl).value)) 
      {
         move = Number(move);
         firstindex= Number(firstindex);  
         lastindex=Number(lastindex);
        var currentindex = Number($$(currentindexctl).value);
         // set current active display to none
       var currentctlid;
        if ((currentindex >= firstindex) && (currentindex <= lastindex)) 
       { 
            currentctlid = ctlidprefix + String(currentindex);
            $$(currentctlid).style.display = 'none';
        } 
        
         // find next control to display  
         currentindex = currentindex + move;
         if (currentindex > lastindex)
         { 
            currentindex = firstindex;
         }
         else if (currentindex < firstindex) 
         {
            currentindex = lastindex;
         }
        if ((currentindex >= firstindex) && (currentindex <= lastindex)) 
        { 
            currentctlid = ctlidprefix + String(currentindex);
            $$(currentctlid).style.display = '';
        } 
         $$(currentindexctl).value = currentindex;

          if (!isNaN($$(autorotatectlid).value)  && (autorotateaction==1) )
          {          
               var setIntervalScript = "rotate('" + ctlidprefix + "', '" + currentindexctl + "', " + move.toString() + ", " + firstindex.toString() + "," + lastindex.toString() + ",'" + autorotatectlid + "',0," + autorotateinterval.toString() + ");";
               $$(autorotatectlid).value = setInterval(setIntervalScript, autorotateinterval);
          }
          else if (!isNaN($$(autorotatectlid).value)  && (autorotateaction==-1) )
          {
            clearInterval(Number($$(autorotatectlid).value));
             $$(autorotatectlid).value = 'manual';
          }       
      }            
   }
  catch(er)
  {  
      // do nothing
  }
  return;  
} 

//-->

