// Slide object script --
//         Copyright 1999 B. Randle Unix Consulting
//                 All Rights Reserved
//   Permission is granted to use this script, or parts of it,
//   with or without modification, for no fee provided the
//   above copyright notice is included.
//   If you have useful ideas or suggestions, feel free to
//   send them to me at billr@coinet.com.
//       Bill Randle    13 April 1999

// definitions and methods for the Slide object
// the data contained in this Slide is a subset of
// the stuff contained in the Zope/Python Slide object

var serverPath = "images/";

// copy the contents of one slide to another
function copySlide(oslide)
{
  this.setFilename(0, oslide.filename[0]);
  this.setFilename(1, oslide.filename[1]);
  this.setFilename(2, oslide.filename[2]);
  this.name = oslide.name;  // Zope/Python slide id
  this.title = oslide.title;  // slide title
  this.info = oslide.info;  // extra text about the image
  this.image.src = oslide.image.src;
  this.atimage.src = oslide.atimage.src;
}

// set the filename to be used when loading the image
// note that this method does not actually load the image;
// you need to use loadImage() to do that.
function setFilename(which, filename)
{
  var fname = filename || "";

  if (fname != "")
  {
    if (fname.charAt(0) != '/' && fname.substr(0,6) != "http:")
      fname = serverPath + fname;
  }
  this.filename[which] = fname;
}

// gets the URL of the specified image
function getImageURL(which)
{
  var idx = which || 0;

  return this.filename[idx];
}

// loads the image specified by the optional filename
// if filename is missing, it uses the filename property
// of the object
function loadImage(which, filename)
{
  if (filename && filename != "")
    this.setFilename(which, filename);

  if (which == 2)
  {
    if (this.filename[which] != "")
      this.atimage.src = this.filename[which];
  }
  else if (this.filename[which] != "")
    this.image.src = this.filename[which];
alert("loading " + this.filename[which]);
}

// constructor for the Slide object (class)
// all arguments are optional
function Slide(name, title, info, loadnow, ifilename, tfilename, atfilename)
{
  this.filename = new Array();

  // save filename(s) as URLs
  // 0 = fullsize image, 1 = thumbnail, 2 = active thumbnail
  this.setFilename(0, ifilename || "");
  this.setFilename(1, tfilename || "");
  this.setFilename(2, atfilename || "");
  this.name = name || "";  // slide id
  this.title = title || "";  // slide title
  this.info = info || "";  // extra text about the image
  this.image = new Image();
  this.atimage = new Image();

  // first try loading the thumbnail and active thumbnail --
  // if it's not specified, then load the full image
  var loadit = loadnow || 0;
  if (loadit && this.filename[1] != "")
  {
    this.image.src = this.filename[1];
    this.atimage.src = this.filename[2];
  }
  else if (loadit && this.filename[0] != "")
    this.image.src = this.filename[0];
}

// additional methods
Slide.prototype.copy = copySlide;
Slide.prototype.setFilename = setFilename;
Slide.prototype.loadImage = loadImage;
Slide.prototype.getImageURL = getImageURL;


