﻿// JScript File

      function ShowNextImage()
      {
          
          //if there is only one image in the array don't bother
          if(popups.length>1){
            
              ParentOfNodeToFade = document.getElementById("ModelHighlightImage");         
              NodeToFade = document.getElementById("ModelHighlightImageInterior");
              nextImageIndex = 1;
              nextParentNodeBackground = 0;
              ElementForBackground = "";
              
              var NodeToFadeDisplay = NodeToFade.style.display;
              
              //if there are more than 2 items you have to be tricky about gettting order right              
              
              if(popups.length>2){
              
                     //get the node that is currently displayed                    
                    if (NodeToFadeDisplay!='none'){
                        ElementForBackground = NodeToFade;
                        ElementToChange = ParentOfNodeToFade;                 
                    }else{
                        ElementForBackground = ParentOfNodeToFade;
                        ElementToChange = NodeToFade;
                    }
                                                
                    nextBackgroundIndex = nextBackgroundIndex + 1;
                    
                    //if you are on the penultimate then start back at the beginning
                    if (nextBackgroundIndex == popups.length){
                        nextBackgroundIndex = 0
                    }

                       
                      ElementToChange.style.background = "#fff url('" + popups[nextBackgroundIndex] + "') no-repeat 0px 0px;";
                      
              }else{
                  NodeToFade.style.background = "url(" + popups[nextImageIndex] + ")";
              }

              Effect.toggle(NodeToFade);                  
          }
                     
          StopTheClock()
      }

        var nextBackgroundIndex = 0;

      function InitializeTimer()
      {
      // Set the length of the timer, in seconds
      var nextBackgroundIndex = 0
      secs = 3;
      StopTheClock();
      StartTheTimer();
      }

      function StopTheClock()
      {
      if(timerRunning)
      clearTimeout(timerID)
      timerRunning = false
      }



      function StartTheTimer()
      {
        
      if (secs==0)
      {
      StopTheClock()
      // Here's where you put something useful that's
      // supposed to happen after the allotted time.
      // For example, you could display a message:
      ShowNextImage()
      InitializeTimer()
      }
      else
      {
      //self.status = secs
      secs = secs - 1
      timerRunning = true
      timerID = self.setTimeout("StartTheTimer()", delay)
      }
      }