﻿//<!--

function rotate(ctlidprefix, currentindexctl, move, firstindex, lastindex, autorotatectlid, autorotateaction, autorotateinterval, playctlid, pausectlid) 
{
   // 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);
        
         // hide the currently displayed item
        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;
        }
        
        // display next item
        if ((currentindex >= firstindex) && (currentindex <= lastindex)) 
        { 
           currentctlid = ctlidprefix + String(currentindex);
           $$(currentctlid).style.display = '';
        } 
        $$(currentindexctl).value = currentindex;

        // setup controls for auto rotate or manual rotate
        if (isNaN($$(autorotatectlid).value)  && (autorotateaction==1) )
        {      
           var setIntervalScript = "rotate('" + ctlidprefix + "', '" + currentindexctl + "', " + move.toString() + ", " + firstindex.toString() + "," + lastindex.toString() + ",'" + autorotatectlid + "',0," + autorotateinterval.toString() + ",'" + playctlid  + "','" + pausectlid  +"');";
           $$(autorotatectlid).value = setInterval(setIntervalScript, autorotateinterval);
           $$(playctlid).style.display = '';
           $$(pausectlid).style.display = 'none';
        }
        else if (!isNaN($$(autorotatectlid).value)  && (autorotateaction==-1) )
        {
           clearInterval(Number($$(autorotatectlid).value));
           $$(autorotatectlid).value = 'manual';
           $$(playctlid).style.display = 'none';
           $$(pausectlid).style.display = '';
         }       
      }            
   }
  catch(er)
  {  
      // do nothing
  }
  return;  
} 

//-->
