function ApshmSlide(src,link,text,target,attr) {
  
  this.src = src;
 
  this.link = link;
 
  this.text = text;
 
  this.target = target;
  
  
  this.attr = attr;

  
  if (document.images) {
    this.image = new Image();
  }

 
  this.loaded = false;

 
  this.load = function() {
   

    if (!document.images) { return; }

    if (!this.loaded) {
      this.image.src = this.src;
      this.loaded = true;
    }
  }

  //--------------------------------------------------
  this.ApshmLink = function() {
    
    var mywindow;

   
    if (!this.link) return;

    
    if (this.target) {

     
      if (this.attr) {
        mywindow = window.open(this.link, this.target, this.attr);
  
      } else {
      
        mywindow = window.open(this.link, this.target);
      }

     
      if (mywindow && mywindow.focus) mywindow.focus();

    } else {
      
      location.href = this.link;
    }
  }
}


function ApshmSlideShow( ApshmSlideName ) {
  
  this.name = ApshmSlideName;

  this.repeat = true;

  this.prefetch = -1;

  
  this.image;

  
  this.textid;

  
  this.textarea;

  this.timeout = 5000;

  this.ApshmSlides = new Array();
  this.current = 0;
  this.timeoutid = 0;

 
  this.add_ApshmSlide = function(ApshmSlide) {
    
  
    var i = this.ApshmSlides.length;
  
    
    if (this.prefetch == -1) {
      ApshmSlide.load();
    }

    this.ApshmSlides[i] = ApshmSlide;
  }


  this.play = function(timeout) {
    
    this.pause();
  
    if (timeout) {
      this.timeout = timeout;
    }
  
    
    if (typeof this.ApshmSlides[ this.current ].timeout != 'undefined') {
      timeout = this.ApshmSlides[ this.current ].timeout;
    } else {
      timeout = this.timeout;
    }

    this.timeoutid = setTimeout( this.name + ".loop()", timeout);
  }

  
  this.pause = function() {
    
  
    if (this.timeoutid != 0) {

      clearTimeout(this.timeoutid);
      this.timeoutid = 0;

    }
  }

  
  this.update = function() {
   
    if (! this.valid_image()) { return; }
  
    
    if (typeof this.pre_update_hook == 'function') {
      this.pre_update_hook();
    }

    var ApshmSlide = this.ApshmSlides[ this.current ];

    
    var dofilter = false;
    if (this.image &&
        typeof this.image.filters != 'undefined' &&
        typeof this.image.filters[0] != 'undefined') {

      dofilter = true;

    }

   
    ApshmSlide.load();
  
 
    if (dofilter) {

     
      if (ApshmSlide.filter &&
          this.image.style &&
          this.image.style.filter) {

        this.image.style.filter = ApshmSlide.filter;

      }
      this.image.filters[0].Apply();
    }

   
    this.image.src = ApshmSlide.image.src;

   
    if (dofilter) {
      this.image.filters[0].Play();
    }

   
    this.display_text();

   
    if (typeof this.post_update_hook == 'function') {
      this.post_update_hook();
    }

   
    if (this.prefetch > 0) {

      var next, prev, count;

    
      next = this.current;
      prev = this.current;
      count = 0;
      do {

        if (++next >= this.ApshmSlides.length) next = 0;
        if (--prev < 0) prev = this.ApshmSlides.length - 1;

        
        this.ApshmSlides[next].load();
        this.ApshmSlides[prev].load();
      } while (++count < this.prefetch);
    }
  }

  
  this.goto_ApshmSlide = function(n) {
    
  
    if (n == -1) {
      n = this.ApshmSlides.length - 1;
    }
  
    if (n < this.ApshmSlides.length && n >= 0) {
      this.current = n;
    }
  
    this.update();
  }


  //--------------------------------------------------
  this.goto_random_ApshmSlide = function(include_current) {
   
    var i;

    
    if (this.ApshmSlides.length > 1) {

      do {
        i = Math.floor(Math.random()*this.ApshmSlides.length);
      } while (i == this.current);
 
     
      this.goto_ApshmSlide(i);
    }
  }


  this.next = function() {
    
    if (this.current < this.ApshmSlides.length - 1) {
      this.current++;
    } else if (this.repeat) {
      this.current = 0;
    }

    this.update();
  }


  
  this.previous = function() {
    
    if (this.current > 0) {
      this.current--;
    } else if (this.repeat) {
      this.current = this.ApshmSlides.length - 1;
    }
  
    this.update();
  }


  this.shuffle = function() {
   
    var i, i2, ApshmSlides_copy, ApshmSlides_randomized;

    
    ApshmSlides_copy = new Array();
    for (i = 0; i < this.ApshmSlides.length; i++) {
      ApshmSlides_copy[i] = this.ApshmSlides[i];
    }

    ApshmSlides_randomized = new Array();


    do {

   
      i = Math.floor(Math.random()*ApshmSlides_copy.length);

      ApshmSlides_randomized[ ApshmSlides_randomized.length ] =
        ApshmSlides_copy[i];

      for (i2 = i + 1; i2 < ApshmSlides_copy.length; i2++) {
        ApshmSlides_copy[i2 - 1] = ApshmSlides_copy[i2];
      }
      ApshmSlides_copy.length--;


    } while (ApshmSlides_copy.length);

    this.ApshmSlides = ApshmSlides_randomized;
  }


  this.get_text = function() {
   
    return(this.ApshmSlides[ this.current ].text);
  }


 this.get_all_text = function(before_ApshmSlide, after_ApshmSlide) {
   
    all_text = "";
  
    
    for (i=0; i < this.ApshmSlides.length; i++) {
  
      ApshmSlide = this.ApshmSlides[i];
    
      if (ApshmSlide.text) {
        all_text += before_ApshmSlide + ApshmSlide.text + after_ApshmSlide;
      }
  
    }
  
    return(all_text);
  }


  this.display_text = function(text) {
    
    if (!text) {
      text = this.ApshmSlides[ this.current ].text;
    }
  
    if (this.textarea && typeof this.textarea.value != 'undefined') {
      this.textarea.value = text;
    }

    
    if (this.textid) {

      r = this.getElementById(this.textid);
      if (!r) { return false; }
      if (typeof r.innerHTML == 'undefined') { return false; }

     
      r.innerHTML = text;
    }
  }



  this.ApshmLink = function() {
   
    this.ApshmSlides[ this.current ].ApshmLink();
  }


   this.save_position = function(cookiename) {
    
  
    if (!cookiename) {
      cookiename = this.name + '_ApshmSlideShow';
    }
  
    document.cookie = cookiename + '=' + this.current;
  }


   this.restore_position = function(cookiename) {
  
  
    if (!cookiename) {
      cookiename = this.name + '_ApshmSlideShow';
    }
  
    var search = cookiename + "=";
  
    if (document.cookie.length > 0) {
      offset = document.cookie.indexOf(search);
       if (offset != -1) { 
        offset += search.length;
         end = document.cookie.indexOf(";", offset);
        if (end == -1) end = document.cookie.length;
        this.current = parseInt(unescape(document.cookie.substring(offset, end)));
        }
     }
  }


  this.noscript = function() {
  
    $html = "\n";
  
 
    for (i=0; i < this.ApshmSlides.length; i++) {
  
      ApshmSlide = this.ApshmSlides[i];
  
      $html += '<P>';
  
      if (ApshmSlide.link) {
        $html += '<a href="' + ApshmSlide.link + '">';
      }
  
      $html += '<img src="' + ApshmSlide.src + '" ALT="ApshmSlideShow image">';
  
      if (ApshmSlide.link) {
        $html += "<\/a>";
      }
  
      if (ApshmSlide.text) {
        $html += "<BR>\n" + ApshmSlide.text;
      }
  
      $html += "<\/P>" + "\n\n";
    }
  
   
    $html = $html.replace(/\&/g, "&amp;" );
    $html = $html.replace(/</g, "&lt;" );
    $html = $html.replace(/>/g, "&gt;" );
  
    return('<pre>' + $html + '</pre>');
  }


   this.loop = function() {
     if (this.current < this.ApshmSlides.length - 1) {
      next_ApshmSlide = this.ApshmSlides[this.current + 1];
      if (next_ApshmSlide.image.complete == null || next_ApshmSlide.image.complete) {
        this.next();
      }
    } else { 
      this.next();
    }
    
 
    this.play( );
  }


  this.valid_image = function() {
   
    if (!this.image)
    {
      return false;
    }
    else {
      return true;
    }
  }

  this.getElementById = function(element_id) {
  
    if (document.getElementById) {
      return document.getElementById(element_id);
    }
    else if (document.all) {
      return document.all[element_id];
    }
    else if (document.layers) {
      return document.layers[element_id];
    } else {
      return undefined;
    }
  }
  

   this.set_image = function(imageobject) {
 
    if (!document.images)
      return;
    this.image = imageobject;
  }


  this.set_textarea = function(textareaobject) {
  
    this.textarea = textareaobject;
    this.display_text();
  }

   this.set_textid = function(textidstr) {
    
    this.textid = textidstr;
    this.display_text();
  }
}

ApshmSlides = new ApshmSlideShow("ApshmSlides");
ApshmSlides.timeout = 5000;
ApshmSlides.prefetch = -1;
ApshmSlides.repeat = true;