   window.focus();

   function MM_swapImgRestore() { //v3.0
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}
	
	function MM_preloadImages() { //v3.0
	  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}
	
	function MM_findObj(n, d) { //v3.0
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
	}
	
	function MM_swapImage() { //v3.0
	  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}

   //Preload buttons
   MM_preloadImages('b_2_autoplay.gif');

   //Determines which viewer to use based on imageType
   function getAppletType(imageType) {
      var appletType;

      if (imageType == imgSingleorWide || imageType == img360nonWarped)
         appletType = vtApplet;
      else
         appletType = ptApplet;
      
      return appletType
   }

   function getAppletLayerReference(appletType) {
      var appletLayerRef;
      
      if (appletType == vtApplet) {
         if (isNetscape) 
           appletLayerRef = document.layers['vtAppletLayer'];
         else
           appletLayerRef = document.all.vtAppletLayer;
      } else {
         if (isNetscape)
           appletLayerRef = document.layers['ptAppletLayer'];
         else
           appletLayerRef = document.all.ptAppletLayer;
      }
      return appletLayerRef;   
   }

   //Returns a reference to the viewer applet based on appletType
   function getAppletReference(appletType) {
      var appletRef;

      if (appletType == vtApplet) {
         if (isNetscape)
            appletRef = document.layers['vtAppletLayer'].document.applets['VTviewer'];
         else
            appletRef = document.all.VTviewer;
      } else {
         if (isNetscape)
            appletRef = document.layers['ptAppletLayer'].document.applets['PTviewer'];
         else
            appletRef = document.all.PTviewer;
      }
      return appletRef;
   }

   function getTextAppletReference() {
     var textAppletRef;
     if (isNetscape) {
       if (document.layers['TextLayer']) {
         textAppletRef = document.layers['TextLayer'].document.applets['TextApplet'];
       }
     } else
        textAppletRef = document.all.TextApplet;   
     return textAppletRef;
   }

   function onMouseClick(x,y) {
     if (autoPlayMode) stopSlideShow();
     return true;
   }
    
   var firstImagePreloaded = false;

   function onPreloadImage(filename) {
     if (!firstImagePreloaded) {
       firstImagePreloaded = true;
       if (curAppletType == ptApplet) {
         onPTImageLoad();
       }
       if (autoPlayMode && tourSlides>0) {
         MM_swapImage('autoplay_button','','b_2_autoplay.gif',1);
         handleAutoPlay()
       }
     }
   }

   var ptImageLoaded = false;
   function onPTImageLoad() {
    var viewerApplet = getAppletReference(ptApplet);        
    ptImageLoaded = true;
    viewerApplet.showHS();
    //monitorPTRotation(true);
	 ptRotationComplete=false;
	 ptPrevAngle=0;
	setTimeout('monitorPTRotation(true)',250);
   }
   
   var ptRotationComplete = false;
   var ptPrevAngle = 0;
   var otPrevMouseX = -1;
   var monitorPTRotationTimeoutID =0;

   function monitorPTRotation(firstTime) {
     if (curAppletType == ptApplet && autoPlayMode) {

       var viewerApplet = getAppletReference(ptApplet);        
       var angle = viewerApplet.pan();
       var mouseX = viewerApplet.get_x();
       if (angle < 0) angle=360 + angle;
       if (firstTime) {
         ptRotationComplete=false;
         ptPrevAngle=0;
       }

       if (angle < ptPrevAngle) {
         ptRotationComplete=true;
       } else if (angle==ptPrevAngle && autoPlayMode) {
         stopSlideShow();
       } else {
         ptPrevAngle = angle;
         ptPrevMouseX = mouseX;
         monitorPTRotationTimeoutID = setTimeout('monitorPTRotation(false)',250);
       }
     } 
   }


   //Loads a very small non-panoramic into the applet to
   //minimize memory and background processing.
   function stopApplet(appletType) {
      var viewerApplet = getAppletReference(appletType);
      var preloadImageFolder = "";

      //Assign the image
      if (appletType == vtApplet) {
         if (tourRelativePath.length != 0) preloadImageFolder = "/applets/VTViewer/";
         viewerApplet.loadImage(preloadImageFolder + 'preload.jpg',false,1,30,false);
      }
      else {
         viewerApplet.stopAutoPan();
      }      
   }
   

   //Show the Caption and Description
   function showSlideText() {
     var textAppletRef = getTextAppletReference();
    
     if (textAppletRef) {
       textAppletRef.setTitle(slides[curSlideIndex].caption);
       textAppletRef.setText(slides[curSlideIndex].description);
     } else {
        var slideCaption = "<table width='344' height='24' border='0' cellpadding='0' cellspacing='0'><tr valign='middle' align='center'><td><font size='3' face='arial' color='"+ captionFontColor + "'><b>" + slides[curSlideIndex].caption + "</b></font></td></tr></table>"
        var slideDescription = "<table><tr><td><font face='arial' size='2' color='#000000'>" + slides[curSlideIndex].description + "</font></td></tr></table>"
    
        if (isNetscape)
           //Note: this routine is located in vt4_ns.js
           showSlideTextNS4( slideCaption, slideDescription,document.layers['CaptionLayer'], document.layers['ViewPortLayer'].document.layers['DescriptionLayer']);
        else {
           document.all.CaptionLayer.innerHTML = slideCaption
           //This resets the scrollbar starting position
           document.all.DescriptionLayer.innerHTML = "&nbsp;&nbsp;"         
           document.all.DescriptionLayer.innerHTML = slideDescription;
        }    
     }
   }

   function showSlide(clicked,direction) {
      ptImageLoaded = false;

      if (tourSlides <=0) return;

      // Can be called from click event or autoplay event. Use 'clicked' parameter to determine which one.
      if (clicked && autoPlayMode) stopSlideShow();
    
      if (direction == 'N' || direction == 'n') {
         if (curSlideIndex == (slides.length -1))
            curSlideIndex = 0;
         else 
            curSlideIndex = curSlideIndex + 1;
         prevSlideIndex = -1;
      } else if (direction == 'P' || direction == 'p') {       
         if (prevSlideIndex != -1)
            curSlideIndex = prevSlideIndex;
         else if (curSlideIndex == 0)
            curSlideIndex = slides.length-1;
         else 
            curSlideIndex = curSlideIndex - 1;
         prevSlideIndex = -1;
      }
      
      //We show the slide text here so it doesn't display until the image has loaded.
      showSlideText();

		  var appletType = getAppletType(slides[curSlideIndex].imageType);
      var viewerApplet = getAppletReference(appletType);
      
      //Hide or Show layers as needed
      if (appletType != curAppletType) {

        if (curAppletType == ptApplet) stopApplet(curAppletType);
       //Under IE5, the LivePicture applet will unload if we hide the layer.
			//So, we'll move it off screen and back as a workaround.
			//waw 9/9/99
         var curAppletLayerRef = getAppletLayerReference(curAppletType);
         var newAppletLayerRef = getAppletLayerReference(appletType);
         if (isNetscape) {
           curAppletLayerRef.left=900;
           newAppletLayerRef.left = appletLeftPos;
         } else {
           curAppletLayerRef.style.left=900;
           newAppletLayerRef.style.left = appletLeftPos;
         }
     }
	      
      //Assign the image
      if (appletType == vtApplet) {
         var is360 =  (slides[curSlideIndex].imageType== img360nonWarped);          
         viewerApplet.loadImage(tourRelativePath + slides[curSlideIndex].imageFile,is360,1,30,vtHotSpots[curSlideIndex]);
	   } else {
         viewerApplet.newPano('{file=' + tourRelativePath + slides[curSlideIndex].imageFile + '} ' + ptIVRParams[curSlideIndex] + ' {inits=javascript:onPTImageLoad();} ' + ptHotSpots[curSlideIndex]);
      }

      //stop previous applet from running in background
      if (appletType != curAppletType) {
        setTimeout('stopApplet(' + curAppletType + ')',500);
      }
      curAppletType = appletType;

      //Reset timer flag
		  autoPlayTimerStarted =false;
      if (curSlideIndex > -1) handleAutoPlay();

      loadNextSlide();
   }

   function isNextImageIVR() {
      // determine the next slide index
      var nextSlideIndex;
      if (curSlideIndex == slides.length -1 )
         nextSlideIndex = 0;
      else
         nextSlideIndex = curSlideIndex+1;

      return (getAppletType(slides[nextSlideIndex].imageType) == ptApplet);
   }


   //Buffer the next image
   function loadNextSlide() {    
      // determine the next slide index
      var nextSlideIndex;
      if (curSlideIndex == slides.length -1 )
         nextSlideIndex = 0;
      else
         nextSlideIndex = curSlideIndex+1;

      var appletType = getAppletType(slides[nextSlideIndex].imageType);
      if (appletType == vtApplet) {
         var viewerApplet = getAppletReference(vtApplet);        
         viewerApplet.preloadImage(tourRelativePath + slides[nextSlideIndex].imageFile);
      }
   }

   function handleAutoPlay() {
      if (autoPlayMode) {   

         //Get duration for current slide and convert to milliseconds
         slideDuration = slides[curSlideIndex].duration * 1000; 
      
         // If zero, default to 15 seconds
         if (slideDuration == 0) slideDuration = 15000;
         
         if (curAppletType == vtApplet) {
           
           var viewerApplet = getAppletReference(vtApplet);

            //Wait for image to load first
           if (viewerApplet.imageLoaded() ==false) {
			    
             imageLoadTimeoutID = setTimeout("handleAutoPlay();",250);
             return;
           } 

           //Set start time
           if (autoPlayTimerStarted==false) {
              autoPlayTimerStarted=true;
              slideStartTime = new Date();
           }
           
           //Wait for rotation to complete
           var nextImagePreloaded;
           if (isNextImageIVR())
             nextImagePreloaded = true;
           else
             nextImagePreloaded = viewerApplet.preloadImageLoaded();
             
           if (viewerApplet.rotationComplete() ==false || nextImagePreloaded==false) {
             imageLoadTimeoutID = setTimeout("handleAutoPlay();",250);
             return;			  
           }
         } else {
         
            //Wait for image to load first
           if (ptImageLoaded ==false) {
             imageLoadTimeoutID = setTimeout("handleAutoPlay();",250);
             return;
           } 
     
           //Set start time
           if (autoPlayTimerStarted==false) {
              autoPlayTimerStarted=true;
              slideStartTime = new Date();
           }
     
           if (ptRotationComplete ==false) {
             imageLoadTimeoutID = setTimeout("handleAutoPlay();",250);
             return;			  
           }
         }       
         
         var currentTime = new Date();
         var elapsedTime = (currentTime.getTime() - slideStartTime.getTime());
         var remainingTime = slideDuration - elapsedTime;
         //alert('elapsedTime=> ' + elapsedTime + '\n' + 'remainingTime=> ' + remainingTime);
         if (remainingTime > 0)
           //Set the timer event
           autoPlayTimeoutID = setTimeout("showSlide(false,'N')",remainingTime);
         else
           showSlide(false,'N');
      }
   }

   function startSlideShow() {
      //We can't use the hiLite function here because preloaded gifs
      //don't run the animation.  So, we have to load the gif directly.
      MM_swapImage('autoplay_button','','b_2_autoplay.gif',1);
      autoPlayMode = true;
      clearTimeout(monitorPTRotationTimeoutID);
      showSlide(false,'N');
   }

   function stopSlideShow() {
      MM_swapImage('autoplay_button','','transparent.gif',1);
      autoPlayMode = false;
      clearTimeout(imageLoadTimeoutID);
      clearTimeout(monitorPTRotationTimeoutID);
      clearTimeout(autoPlayTimeoutID);
   }

   function toggleSlideShow() {
      if (autoPlayMode)
         stopSlideShow();
      else
         startSlideShow();
   }
    
   function emailFriend() {
      var targetURL="";
      if (tourRelativePath.length == 0) targetURL = "http://" + serverName;
      targetURL = targetURL + "/applets/vt_viewer/emailfriend.asp?T=" + escape(tourID) + "&SK=" + escape(skinID) + "&USER=" + escape(userID) + "&B=" + escape(brokerID) + "&U=" + escape(showTourURL) + "?T=" + escape(tourID);

      features='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,' 
      features += 'resizable=yes,width=400,height=378';
      window.open(targetURL,"EmailFriend",features);  
   }
   
   function emailAgent() {
      var targetURL="";
      if (tourRelativePath.length == 0) targetURL = "http://" + serverName;
      targetURL = targetURL + "/applets/vt_viewer/emailagent.asp?T=" + escape(tourID) + "&USER=" + escape(userID) + "&B=" + escape(brokerID) + "&A=" + escape(agentName) + "&U=" + escape(showTourURL) + "?T=" + escape(tourID); 
      
      features='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,' 
      features += 'resizable=yes,width=400,height=251';
      window.open(targetURL,"EmailAgent",features);    
   }

   function pageAgent() {
      var targetURL="";
      if (tourRelativePath.length == 0) targetURL = "http://" + serverName;
      targetURL = targetURL + "/applets/vt_viewer/emailpager.asp?USER=" + escape(userID) + "&B=" + escape(brokerID) + "&A=" + escape(agentName) + "&T=" +  escape(tourID) + "&TITLE=" +  escape(tourTitle); 

      features='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,' 
      features += 'resizable=yes,width=400,height=232';
      window.open(targetURL,"EmailAgentPager",features);    
   }
  
   function showAgentWebsite() {
      var w,h;
       
      //size to 80% of screen and center
      w =(screen.width * .8);
	   h = (screen.height * .7)
	   x= (screen.width-w)/2;
	   y=0 

      //Define Browser Window Style
      features ='toolbar,location,status,menubar,'; 
      features += 'scrollbars,resizable,width=' + w + ',height=' + h; 
      features += ',top=' + y + ',left=' + x;
      window.open(tourHomeURL,"Home",features);
   }

   function showBannerURL() {
      var w,h;
       
      //size to 80% of screen and center
      w =(screen.width * .8);
	   h = (screen.height * .7)
	   x= (screen.width-w)/2;
	   y=0 

      //Define Browser Window Style
      features ='toolbar,location,status,menubar,'; 
      features += 'scrollbars,resizable,width=' + w + ',height=' + h; 
      features += ',top=' + y + ',left=' + x;
      window.open(tourBannerURL,"Home",features);
   }

   function showVTWebsite() {
      var w,h;
      var targetURL;
      
      //size to 80% of screen and center
      w =(screen.width * .8);
      h = (screen.height * .7)
      x= (screen.width-w)/2;
      y=0 
       
      if (serverName.indexOf('vic-tour')>-1)
        targetURL = 'http://www.vic-tour.com'
      else
        targetURL = 'http://www.visualtour.com'

      //Define Browser Window Style
      features ='toolbar,location,status,menubar,'; 
      features += 'scrollbars,resizable,width=' + w + ',height=' + h; 
      features += ',top=' + y + ',left=' + x;
      window.open(targetURL,"VTWebsite",features);
   }

   //Show the Contact Information under the image
   function showContactInfo() {
      stopSlideShow();
      var textAppletRef = getTextAppletReference();
    
      if (textAppletRef) {
        textAppletRef.setTitle("Contact Information");
        textAppletRef.setText(agentInfo);
      } else {
        var contactTitle = "<table width='344' height='24' border='0' cellpadding='0' cellspacing='0'><tr valign='middle' align='center'><td><font size='3' face='arial' color='#000000'><b>" + "Contact Information" + "</font></b></td></tr></table>"
        var contactInformation = "<font face='arial' size='2' color='#000000'>" + agentInfo + "</font>"

        if (navigator.appName == 'Netscape' && document.layers != null)
           //Note: this routine is located in vt_ns4.js
           showSlideTextNS4( contactTitle, contactInformation,document.layers['CaptionLayer'], document.layers['ViewPortLayer'].document.layers['DescriptionLayer']);
        else {
           document.all.CaptionLayer.innerHTML = contactTitle
           document.all.DescriptionLayer.innerHTML = contactInformation
        }
      }
   }

   //**** Streaming Voice Routines
   var voicePlaying = false;
   var voiceMonitorTimeoutID;
   var voiceMonitorFrequency = 500;  //milliseconds
  
   function toggleVoice() {
      if (voicePlaying) {
         //Stop it
         MM_swapImage('voice_button','','b_voice.gif',1);
         clearTimeout(voiceMonitorTimeoutID);
         voicePlaying = false;
         document.WSAudio.stopPlaying();
      } else {
         //Start it
         MM_swapImage('voice_button','','b_2_voice.gif',1);
         voicePlaying = true;
         document.WSAudio.startPlaying();
      }
   }
  
   function monitorVoiceStream() {
      //This routine will monitor the Streams applet
      //and automatically pop-up the voice button when
      //the stream is done playing
      var statusUnknown = 0;
      var statusBuffering = 1;
      var statusPlaying = 2;
      var statusEOF = 4;
    
      if (voicePlaying) {
         //var status = document.Streams.getStatus();
         var status = document.WSAudio.getStatus();
      
         if (status == statusBuffering || status == statusPlaying)
            //Keep monitoring
            voiceMonitorTimeoutID = setTimeout("monitorVoiceStream()",voiceMonitorFrequency);
      
         else {
            voicePlaying = false;
            MM_swapImage('voice_button','','b_voice.gif',1);

            if (status != statusEOF)
               //There was an error
               alert('Unable to play voice clip. ' + status);
         }     
      }
   }

   function voiceEnd() {
    voicePlaying = false;
    MM_swapImage('voice_button','','b_voice.gif',1);
   }

   var ptHSZoomStep=0;
   function zoomPTHotSpot() {
     var viewerApplet = getAppletReference(ptApplet);        

     if (ptHSZoomStep >= 5) {
       showSlide(true,'C');
     } else {
       viewerApplet.ZoomIn();
       ptHSZoomStep=ptHSZoomStep+1;
       setTimeout("zoomPTHotSpot()",150);
     }
   }

   function activateHotSpot(x,y,imageFile,zoom,relX,relY) {
     //This routine is called from the VTViewer applet
     //when a hotspot is clicked.  It passes the imagefile
     //to jump to.  We do it this way instead of just jumping to
     //the image in the applet so the caption and description are
     //displayed as well.
     var slideIndex = -1;

     //Find the slideIndex 
     for(i=0; i<slides.length; i++) {
       if (slides[i].imageFile.toLowerCase() == imageFile.toLowerCase()) {
         slideIndex = i;
         break;
       }
     }
     if (slideIndex > -1) {
       prevSlideIndex = curSlideIndex;
       curSlideIndex = slideIndex;
       if (curAppletType == ptApplet && zoom) {
         ptHSZoomStep = 0;
         zoomPTHotSpot();
       } else {
        showSlide(true,'C');
       }
     }
   }
