// Universal variables
  var gImg = new Array(); // global - array of images used for preloading 
  var gFrameindex=1;      // global - the current frame to display in a spin image
  var gNumframes;         // global - the total number of frames in a spin image
  var gSpeed;             // global - the speed to spin an image, negative = spin left, positive = spin right, 0 = stop spinning
  var gItem;              // global - the image to spin 
  var gSpin=true;         // global - used for toggling spinning on and off
  
// Pre load images
function preload() {
  if (document.images) {
    for (i=0;i<pImages.length;i++) {
	  gImg[i] = new Image;
	  gImg[i].src = pBase + pImages[i] + pExt
	}
  }
}

// Switch the image specified by item to the version of the images specified by choice
function dispimage(item,choice) {
  if (document.images) {
    document.images[item].src = pBase + item + choice + pExt;
  }
}

// Spin the image with the parameters set with setspin()
function spinimage() { 
  if (gSpeed != 0 && gSpin) { // if gSpeed is 0 or gSpin is false, stop spinning
    dispimage (gItem,gFrameindex);
    if (gSpeed > 0) { // for positive gSpeed's, increment gFrameindex, looping when gNumframes is reached
	  if (gFrameindex == gNumframes) {
	    gFrameindex = 1;
	  } else {
	    gFrameindex++;
	  }
	} else { // for negative gSpeed's, decrement gFrameindex, looping when 1 is reached
	  if (gFrameindex == 1) {
	    gFrameindex = gNumframes;
	  } else {
		gFrameindex--;
	  }
	}
  }
  setTimeout("spinimage()",Math.abs(gSpeed));
}

// Sets the parameters that spinimage uses
function setspin(item,numframes,speed) {
  gItem=item;
  gNumframes=numframes;
  gSpeed=speed;
}

//Toggle spinning
function togglespin() {
  if (gSpin) {
    gSpin=false;
  } else {
    gSpin=true;
  }
}
