function PFObj(image, head, tail, count, initial,
  autorotate, mousecontrol, xcenter, ycenter) {
if (!document.PFObjMovies[image.name]) {
  if (!initial) initial = 0;
  if (!autorotate) autorotate = 0;
  if (!mousecontrol) mousecontrol = 0;
  if (!xcenter) xcenter = 0.5;
  if (!ycenter) ycenter = 0.5;
  new PFObjMovie(image, head, tail, count, initial,
    autorotate, mousecontrol, xcenter, ycenter);
  PFObjShow();
  }
}
function PFObjMouseControl(image, mousecontrol) {
  var t;
  t = document.PFObjMovies[image.name];
  if (t) {t.mousecontrol = mousecontrol}
}
function PFObjAutoRotate(image, autorotate) {
  var t;
  t = document.PFObjMovies[image.name];
  if (t) {
    if (t.running) {
      clearInterval(t.intervalcode);
      t.running = false;
    }
    if (autorotate != 0) {
      t.running = true;
      if (autorotate > 0) {
        t.intervalcode = setInterval("PFObjAuto('" +  image.name + "', 1)", autorotate);
      } else {
        t.intervalcode = setInterval("PFObjAuto('" +  image.name + "', -1)", -autorotate);
      }
    }
  }
}

var PFisNav = PFisNav6 = PFisIE = PFshowing = false;
document.PFObjMovies = new Array();
if ((navigator.appName.indexOf("Netscape") != -1) &&
    (parseInt(navigator.appVersion) >= 4)) {
  PFisNav = true;
  PFisNav6 = parseInt(navigator.appVersion) >= 5;
} else if ((navigator.appName.indexOf("Microsoft") != -1) &&
           (parseInt(navigator.appVersion) >= 4)) {
  PFisIE = true;
} else {}

function PFObjMovie(image, head, tail, count, initial,
  autorotate, mousecontrol, xcenter, ycenter) {
  var p;
  var i;
  var clockwise;

  if ((count != 0) && (PFisNav || PFisIE)) {
    document.PFObjMovies[image.name] = this;
    this.image = image;
    this.oimages = new Array();
    if (count > 0) {
      this.count = count;
      clockwise = true;
    } else {
      this.count = -count;
      clockwise = false;
    }
    this.current = initial;
    this.istart = initial;
    this.xstart = 0;
    this.astart = 0;
    this.moving = false;
    this.loading = true;
    this.autorotate = autorotate;
    this.mousecontrol = mousecontrol;
    this.running = false;
    if ((this.mousecontrol & 6) == 0) {
      this.xcenter = xcenter;
      this.ycenter = ycenter;
    } else {
      this.xcenter = 0;   // force origin to corner
      this.ycenter = 0;   // force origin to corner
    }
  }
  if (PFisNav || PFisIE) {
    if (clockwise) {
      for (i = 0; i < this.count; i++) {
        this.oimages[i] = new Image();
        this.oimages[i].src = head + i + tail;
        this.oimages[i].onload = PFObjShow;
      }
    } else {
      for (i = 0; i < this.count; i++) {
        this.oimages[i] = new Image();
        this.oimages[i].src = head + (this.count - 1 - i) + tail;
        this.oimages[i].onload = PFObjShow;
      }
    }
  }
}

function PFObjSetupXYWH(t) {
  if (PFisIE) {
    t.x = t.xcenter * t.image.offsetWidth;
    t.y = t.ycenter * t.image.offsetHeight;
    t.w = t.image.offsetWidth;
    t.h = t.image.offsetHeight;
  } else if (PFisNav6) {
    t.x = t.image.offsetLeft + t.xcenter * t.image.offsetWidth;
    t.y = t.image.offsetTop + t.ycenter * t.image.offsetHeight;
    t.w = t.image.offsetWidth;
    t.h = t.image.offsetHeight;
  } else if (PFisNav) {
    t.x = t.image.x + t.xcenter * t.image.width;
    t.y = t.image.y + t.ycenter * t.image.height;
    t.w = t.image.width;
    t.h = t.image.height;
  }
}

function PFObjShow() {
  var name;
  var t;
  for (name in document.PFObjMovies) {
    t = document.PFObjMovies[name];
    if (t.loading) {
      t.loading = false;
      var n = 0;
      var i;
      for (i = 0; i < t.count; i++) {
        if (!t.oimages) t.loading = true;
        else if (!t.oimages[i]) t.loading = true;
        else if (!t.oimages[i].complete) t.loading = true;
        else n++;
      }
    }
    if (!t.loading) {
      t.image.src = t.oimages[t.current].src;
      if ((t.autorotate != 0) && !t.running) {
        t.running = true;
        if (t.autorotate > 0) {
          t.intervalcode = setInterval("PFObjAuto('" +  name + "', 1)", t.autorotate);
        } else {
          t.intervalcode = setInterval("PFObjAuto('" +  name + "', -1)", -t.autorotate);
        }
        t.autorotate = 0;
      }
    } else {
      setTimeout("PFObjShow()", 1000);  // in case .onload = PFObjShow doesn't work (IE)
    }
  }
}

function PFObjAuto(name, step) {
  var t;
  t = document.PFObjMovies[name];
  t.current += step;
  while (t.current < 0) t.current += t.count;
  while (t.current >= t.count) t.current -= t.count;
  PFObjShow();
}

function PFObjStartMove(e) {
  var t, x, y;
  if (PFisIE || PFisNav) {
    if (PFisIE) {
      t = document.PFObjMovies[window.event.srcElement.name];
    } else {
      t = document.PFObjMovies[e.target.name];
    }
  }
  if (t && (t.mousecontrol >= 0)) {
    if (PFisIE) {
      t.xstart = window.event.offsetX;
      t.ystart = window.event.offsetY;
    } else {
      t.xstart = e.pageX;
      t.ystart = e.pageY;
    }
    PFObjSetupXYWH(t);
    if ((t.mousecontrol & 6) == 2) {
      // horizontal.
      t.astart = (Math.PI * 2) * (t.xstart - t.x) / t.w;
    } else if ((t.mousecontrol & 6) == 4) {
      // vertical.
      t.astart = (Math.PI * 2) * (t.ystart - t.y) / t.h;
    } else {
      // circles.
      t.astart = Math.atan2(
        (t.xstart - t.x) / t.w,
        (t.ystart - t.y) / t.h);
    }
    t.moving = !isNaN(t.astart);
    t.istart = t.current;
    if (t.moving && t.running) {
      clearInterval(t.intervalcode);
      t.running = false;
    }
  }
}

function PFObjStopMove(e) {
  var t;
  if (PFisIE || PFisNav) {
    if (PFisIE) {
      t = window.event.srcElement;
    } else {
      t = e.target;
    }
    t = document.PFObjMovies[t.name];
  }
  if (t && (t.mousecontrol >= 0)) {
    if (t.running) {
      clearInterval(t.intervalcode);
      t.running = false;
    }
    t.moving = false;
  }
}

function PFObjDoMove(e) {
  var t;
  if (PFisIE || PFisNav) {
    if (PFisIE) {
      t = window.event.srcElement;
    } else {
      t = e.target;
    }
    t = document.PFObjMovies[t.name];
  }
  if (t && (t.mousecontrol >= 0)) {
    if (t.running) {
      clearInterval(t.intervalcode);
      t.running = false;
    }
    if (!t.moving) PFObjStartMove(e);
    if (t.moving) {
      if (PFisIE) {
        t.xcurrent = window.event.offsetX;
        t.ycurrent = window.event.offsetY;
      } else {
        t.xcurrent = e.pageX;
        t.ycurrent = e.pageY;
      }
      PFObjSetupXYWH(t);
      if ((t.mousecontrol & 6) == 2) {
        // horizontal.
        t.acurrent = (Math.PI * 2) * (t.xcurrent - t.x) / t.w;
      } else if ((t.mousecontrol & 6) == 4) {
        // vertical.
        t.acurrent = (Math.PI * 2) * (t.ycurrent - t.y) / t.h;
      } else {
        // circles.
        t.acurrent = Math.atan2(
          (t.xcurrent - t.x) / t.w,
          (t.ycurrent - t.y) / t.h);
      }
      if (!isNaN(t.astart) && !isNaN(t.acurrent)) {
        var i;
        if (t.mousecontrol & 1) {
          // absolute.
          i = Math.floor(t.count - 1 - t.count * t.acurrent / (Math.PI * 2));
        } else {
          // relative.
          i = t.istart - Math.round(t.count * (t.acurrent - t.astart) / (Math.PI * 2));
        }
        while (i < 0) i += t.count;
        while (i >= t.count) i -= t.count;
        if (i != t.current) {
          t.current = i;
          PFObjShow();
        }
      }
    }
  }
}

function PFObjInit() {
  document.cookie = "pnt=wht";
  document.onmouseover = PFObjStartMove;
  document.onmouseout = PFObjStopMove;
  document.onmousemove = PFObjDoMove;
  if (PFisNav) {
    // Set up event handling.
    document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT | Event.MOUSEMOVE);
  }
}
