//Control slideshows from SiteSpinner. Include this file in your page
//V1.1:Extended to now include slideshows with pages or images in i-frames
//V1.2:No longer updates the window history
//V1.3:Fixed problem with needing multiple next/prev clicks to get started
//V1.3 by Bruceee, 06 Oct 2005

function SlideShow(Slides)
//Setup code for a slideshow as a Javascript object
{
this.LastShown = null; //ID of last slide shown
this.SlideNum = 0;     //Index of current slide being displayed
this.TimerID=0;        //ID of timer so we can stop it
this.Interval=0;       //Pause in secs between timed slides
this.Iframe=false;     //I-frame slideshows are different
this.target=0;         //Name of i-frame being targetted
this.folder='';        //folder where i-frame files are
this.extn='.html';     //extension of files in i-frame
if (Slides!=undefined) {
  this.List = Slides.split(","); //String list of slides in this slideshow
  this.Iframe=(Slides.search("[A-Za-z]")>=0);//Anything with no alphabetic char is in-page
  if (this.Iframe) {
    //extract folder name if any from first file
    Path=this.List[0].split("/") 
    if (Path.length>1) {   
      for (i=0;i<Path.length-1;i++) {
        this.folder+=Path[i]+'/'
      }
      this.List[0]=Path[Path.length-1]
    } 
    //extract file extension if any from first file
    Extn=this.List[0].split(".")
    if (Extn.length>2) {alert('Slideshow: "'+this.List[0]+'" should have only one dot')}
    if (Extn.length>1) {
      this.extn='.'+Extn[1]
      this.List[0]=Extn[0]
    }   
  } 
}
this.hide = Hide;
this.show = showImage;
this.nextslide=nextSlide;
this.prevslide=prevSlide;
this.starttimer = startTimer;
this.stoptimer=stopTimer;
}

function Hide() {
//Hide last shown image
var HiddenID=this.LastShown;
if (HiddenID==null) { //hide all slides as a precaution
  if (this.List!=null) {
    for (var i=0;i<this.List.length;i++) {
      this.LastShown=document.getElementById("Oobj" + this.List[i]);
      this.LastShown.style.visibility = "hidden";
      }
    }
  }
else {HiddenID.style.visibility = "hidden"}
}

function showImage(aID)
//Hide existing displayed image, then display a new one
{
if (this.Iframe) {
  frames[this.target].location.replace(this.folder+aID+this.extn)
}
  else {
    this.hide (); 
    this.LastShown=document.getElementById("Oobj" + aID);
    if (this.LastShown==null) {
      alert('Can\'t show image obj'+aID+' -- not on this page')
    } 
    else {
      this.LastShown.style.visibility = "visible";
    }
  }
}

function nextSlide()
//Display next slide of a series
{
this.SlideNum++;
if (this.SlideNum >= this.List.length) {
  this.SlideNum=0;
 }
this.show(this.List[this.SlideNum]);
}

function prevSlide()
//Display previous slide of a series
{
this.SlideNum--;
if (this.SlideNum < 0) {
  this.SlideNum=this.List.length-1;
}
this.show(this.List[this.SlideNum]);
}

function startTimer(aName, aInterval) {
//Start a timed slideshow
if (this.TimerID==0){
  this.Interval = aInterval;
  this.TimerID = setInterval(aName+".nextslide()",aInterval*1000)
 }
}

function stopTimer() {
//Stop a timed slideshow
clearInterval(this.TimerID)
this.TimerID=0
}
//</script>


