function SetOpacity(img, opacity)
{ if (img.style.opacity == null)
  { img.filters.alpha.opacity = opacity;
  }
  else
  { img.style.opacity = opacity / 100;
  };
};

function GetOpacity(img)
{ if (img.style.opacity == null)
  { return img.filters.alpha.opacity;
  }
  else
  { return Math.floor (img.style.opacity * 100);
  };
};

var FadeSpeed = 3;
var FadeMin = 30;
var FadeMax = 100;
function FadeIn(ImageId)
{ img = document.getElementById(ImageId);
  if (img.lowsrc)
  { clearTimeout (img.lowsrc);
  }; 
  if (GetOpacity (img) + FadeSpeed < FadeMax)
  { SetOpacity (img, GetOpacity (img) + FadeSpeed);
    img.lowsrc = setTimeout("FadeIn(\"" + ImageId + "\")", 10);
  }
  else
  { SetOpacity (img, FadeMax);
    img.lowsrc = "";
  };
};
function FadeOut(ImageId)
{ img = document.getElementById(ImageId);
  if (img.lowsrc)
  { clearTimeout (img.lowsrc);
  }; 
  if (GetOpacity (img) - FadeSpeed > FadeMin)
  { SetOpacity (img, GetOpacity (img) - FadeSpeed);
    img.lowsrc = setTimeout("FadeOut(\"" + ImageId + "\")",10);
  }
  else
  { SetOpacity (img, FadeMin);
    img.lowsrc = "";
  };
};

function Faded(ImageId)
{ img = document.getElementById(ImageId);
  SetOpacity (img, FadeMin);
};

var ZoomSpeed = 5;
var ZoomMin = 80;
function ZoomIn (ImageId)
{ img = document.getElementById(ImageId);
  if (!img.name)
  { orgwidth = img.width;
    img.name = orgwidth;
  }
  else
  { orgwidth = parseInt(img.name);
  };
  if (img.lowsrc)
  { clearTimeout (img.lowsrc);
  }; 
  if (img.width + ZoomSpeed < orgwidth)
  { img.width += ZoomSpeed;
    img.lowsrc = setTimeout ("ZoomIn(\"" + ImageId + "\")", 5);
  }
  else
  { img.width = orgwidth;
    img.lowsrc = "";
  };
};
function ZoomOut (ImageId)
{ img = document.getElementById(ImageId);
  if (!img.name)
  { orgwidth = img.width;
    img.name = orgwidth;
  }
  else
  { orgwidth = parseInt(img.name);
  };
  if (img.lowsrc)
  { clearTimeout (img.lowsrc);
  }; 
  if (img.width - ZoomSpeed > ZoomMin)
  { img.width -= ZoomSpeed;
    img.lowsrc = setTimeout ("ZoomOut(\"" + ImageId + "\")", 5);
  }
  else
  { img.width = ZoomMin;
    img.lowsrc = "";
  };
};
function ZoomIcon (ImageId)
{ img = document.getElementById(ImageId);
  if (!img.name)
  { img.name = img.width;
  };
  if (img.lowsrc)
  { clearTimeout (img.lowsrc);
  }; 
  img.width = ZoomMin;
  img.lowsrc = "";
};

var TurnSpeed = 5;
function TurnLeft (ImageId)
{ imgbase = ImageId.substring(0, ImageId.indexOf("."))
  imgr = document.getElementById (imgbase + ".r");
  imgl = document.getElementById (imgbase + ".l");
  if (imgr.name)
  { orgwidth = parseInt (imgr.name);
    angle = parseInt (imgl.name) + TurnSpeed;
  }
  else
  { orgwidth = imgr.width;
    imgr.name = orgwidth;
    imgr.style.width = imgr.width;
    imgr.style.height = imgr.height;
    imgl.style.height = imgr.height;
    angle = 0;
  };
  if (imgr.lowsrc)
  { clearTimeout (imgr.lowsrc);
  }; 
  if (angle < 180)
  { imgwidth = orgwidth * Math.cos(Math.PI * (angle / 180));
    if (imgwidth >= 0)
    { imgr.style.width = imgwidth;
      imgl.border = 0;
      imgl.style.width = 0;
    }
    else
    { imgr.style.width = 0;
      imgl.border = 1;
      imgl.style.width = -imgwidth;
      imgl.style.left = parseInt(imgr.style.left) + imgwidth;
    };
    imgr.lowsrc = setTimeout ("TurnLeft(\"" + imgbase + ".r\")", 5);
  }
  else
  { imgl.style.width = orgwidth;
    imgl.style.left = parseInt(imgr.style.left) - orgwidth - 1;
    angle = 180;
    imgr.lowsrc = "";
  };
  imgl.name = angle;
};
function TurnRight (ImageId)
{ imgbase = ImageId.substring(0, ImageId.indexOf("."))
  imgr = document.getElementById (imgbase + ".r");
  imgl = document.getElementById (imgbase + ".l");
  if (imgr.name)
  { orgwidth = parseInt (imgr.name);
    angle = parseInt (imgl.name) - TurnSpeed;
  }
  else
  { orgwidth = imgr.width;
    imgr.name = orgwidth;
    imgr.style.width = imgr.width;
    imgr.style.height = imgr.height;
    imgl.style.height = imgr.height;
    angle = 0;
  };
  if (imgr.lowsrc)
  { clearTimeout (imgr.lowsrc);
  }; 
  if (angle > 0)
  { imgwidth = orgwidth * Math.cos(Math.PI * (angle / 180));
    if (imgwidth >= 0)
    { imgr.style.width = imgwidth;
      imgl.border = 0;
      imgl.style.width = 0;
    }
    else
    { imgr.style.width = 0;
      imgl.border = 1;
      imgl.style.width = -imgwidth;
      imgl.style.left = parseInt(imgr.style.left) + imgwidth;
    };
    imgr.lowsrc = setTimeout ("TurnRight(\"" + imgbase + ".l\")", 5);
  }
  else
  { imgr.style.width = orgwidth;
    angle = 0;
    imgr.lowsrc = "";
  };
  imgl.name = angle;
};

function SlideStart(FormId, ImageId)
{ frm = document.getElementById(FormId);
  img = document.getElementById(ImageId);
  if (!img.name)
  { index = 0;
  }
  else
  { index = parseInt(img.name);
  };
  if (index >= frm.elements.length)
  { index = 0;
  };
  img.src = frm.elements[index].name;
  img.lowsrc = setTimeout("SlideStart('" + FormId + "', '" + ImageId + "')",
                          frm.elements[index].value * 1000);
  index += 1;
  img.name = index;
};
function SlideStop(ImageId)
{ img = document.getElementById(ImageId);
  if (img.lowsrc)
  { clearTimeout (img.lowsrc);
  }; 
};

FlipSpeed = 5;
function FlipLeft (ImageId)
{ imgbase = ImageId.substring(0, ImageId.indexOf("."))
  imgf = document.getElementById (imgbase + ".f");
  imgb = document.getElementById (imgbase + ".b");
  if (imgf.name)
  { orgwidth = parseInt (imgf.name);
    angle = parseInt (imgb.name) + FlipSpeed;
    center = parseInt (imgb.title)
  }
  else
  { orgwidth = imgf.width;
    imgf.name = orgwidth;
    imgf.style.width = imgf.width;
    imgf.style.height = imgf.height;
    imgb.style.height = imgf.height;
    angle = 0;
    center = parseInt(imgf.style.left) + (parseInt(imgf.width) / 2);
    imgb.title = center
  };
  imgb.name = angle;
  if (imgf.title)
  { clearTimeout (imgf.title);
  }; 
  if (angle < 180)
  { imgwidth = orgwidth * Math.cos(Math.PI * (angle / 180));
   if (imgwidth >= 0)
    { imgf.style.display = "";
      imgf.style.width = imgwidth;
      imgf.style.left = center - (imgwidth / 2);
      imgb.style.display = "none";
      imgb.style.width = 0;
    }
    else
    { imgf.style.display = "none";
      imgb.style.display = "";
      imgb.style.width = -imgwidth;
      imgb.style.left = center - (-imgwidth / 2);
    };
    imgf.title = setTimeout ("FlipLeft(\"" + imgbase + ".f\")", 5);
  }
  else
  { imgb.name = 180;
    imgb.title = "";
    imgf.style.display = "none";
    imgb.style.width = orgwidth;
    imgb.style.left = center - (orgwidth / 2);
    imgf.title = "";
  };
};
function FlipRight (ImageId)
{ imgbase = ImageId.substring(0, ImageId.indexOf("."))
  imgf = document.getElementById (imgbase + ".f");
  imgb = document.getElementById (imgbase + ".b");
  if (imgf.name)
  { orgwidth = parseInt (imgf.name);
    angle = parseInt (imgb.name) - FlipSpeed;
    center = parseInt (imgb.title)
  }
  else
  { orgwidth = imgf.width;
    imgf.name = orgwidth;
    imgf.style.width = imgf.width;
    imgf.style.height = imgf.height;
    imgb.style.height = imgf.height;
    angle = 0;
    center = parseInt(imgb.style.left) + (parseInt(imgb.width) / 2);
    imgb.title = center
  };
  imgb.name = angle;
  if (imgf.title)
  { clearTimeout (imgf.title);
  }; 
  if (angle > 0)
  { imgwidth = orgwidth * Math.cos(Math.PI * (angle / 180));
    if (imgwidth >= 0)
    { imgf.style.display = "";
      imgf.style.width = imgwidth;
      imgf.style.left = center - (imgwidth / 2);
      imgb.style.display = "none";
    }
    else
    { imgf.style.display = "none";
      imgb.style.display = "";
      imgb.style.width = -imgwidth;
      imgb.style.left = center - (-imgwidth / 2);
    };
    imgf.title = setTimeout ("FlipRight(\"" + imgbase + ".b\")", 5);
  }
  else
  { imgb.name = 0;
    imgb.title = "";
    imgb.style.display = "none";
    imgf.style.width = orgwidth;
    imgf.style.left = center - (orgwidth / 2);
    imgf.title = "";
  };
};


FadeMin = 31;
FadeMax = 100;
FadeSpeed = 2;
FadeInt = 30;

function SlideFadeIn(FormId, ImageId)
{ img = document.getElementById(ImageId);
  if (img.lowsrc)
  { clearTimeout (img.lowsrc);
  }; 
  if (GetOpacity (img) + FadeSpeed < FadeMax)
  { SetOpacity (img, GetOpacity (img) + FadeSpeed);
    img.lowsrc = setTimeout("SlideFadeIn('" + FormId + "', '" + ImageId + "')", FadeInt);
  }
  else
  { SetOpacity (img, FadeMax);
    SlideFadeOut (FormId, ImageId);
  };
};
function SlideFadeOut(FormId, ImageId)
{ img = document.getElementById(ImageId);
  if (img.lowsrc)
  { clearTimeout (img.lowsrc);
  }; 
  if (GetOpacity (img) - FadeSpeed > FadeMin)
  { SetOpacity (img, GetOpacity(img) - FadeSpeed);
    img.lowsrc = setTimeout("SlideFadeOut('" + FormId + "', '" + ImageId + "')", FadeInt);
  }
  else
  { if (GetOpacity (img) - FadeSpeed > 0)
    { SetOpacity (img, GetOpacity(img) - FadeSpeed);
      img.lowsrc = setTimeout("SlideFadeOut('" + FormId + "', '" + ImageId + "')", FadeInt);
    }
    else
    { SetOpacity (img, 0);
      img.lowsrc = "";
    };
    if (GetOpacity (img) + FadeSpeed > FadeMin)
    { SlideFade (FormId);
    };
  };
};
function SlideFade(FormId)
{ frm = document.getElementById(FormId);
  if (!frm.name)
  { index = 0;
  }
  else
  { index = parseInt(frm.name);
  };
  if (index >= frm.elements.length)
  { index = 0;
  };
  SlideFadeIn (FormId, frm.elements[index].value);
  index += 1;
  frm.name = index;
};

MoveSpeed = 5;
function MoveHor (ObjId, Dist)
{ obj = document.getElementById(ObjId);
  if (!obj.name)
  { orgpos = parseInt(obj.style.left);
    obj.name = orgpos;
  }
  else
  { orgpos = parseInt(obj.name);
  };
  speed = MoveSpeed * (Dist / Math.abs(Dist));
  if ((Dist > 0 && parseInt(obj.style.left) + speed < orgpos + Dist) ||
      (Dist < 0 && parseInt(obj.style.left) + speed > orgpos + Dist))
  { obj.style.left = parseInt(obj.style.left) + speed;
    toid = setTimeout ("MoveHor('" + ObjId + "', " + Dist + ")", 5);
  }
  else
  { obj.style.left = orgpos + Dist;
  };
};
function MoveVert (ObjId, Dist)
{ obj = document.getElementById(ObjId);
  if (!obj.name)
  { orgpos = parseInt(obj.style.top);
    obj.name = orgpos;
  }
  else
  { orgpos = parseInt(obj.name);
  };
  speed = MoveSpeed * (Dist / Math.abs(Dist));
  if ((Dist > 0 && parseInt(obj.style.top) + speed < orgpos + Dist) ||
      (Dist < 0 && parseInt(obj.style.top) + speed > orgpos + Dist))
  { obj.style.top = parseInt(obj.style.top) + speed;
    toid = setTimeout ("MoveVert('" + ObjId + "', " + Dist + ")", 5);
  }
  else
  { obj.style.top = orgpos + Dist;
  };
};

TextDelay = 3;
function TypeText (DivId, Text)
{ div = document.getElementById(DivId);
  txt = new String (Text)
  if (!div.name)
  { len = 1;
  }
  else
  { len = parseInt(div.name);
  };
  div.name = len + 1;
  if (len <= txt.length)
  { div.innerText = txt.substring (0, len);
    toid = setTimeout ("TypeText('" + DivId + "', '" + Text + "')", TextDelay * 50);
  }
  else
  { div.name = "";
  };
};
function BackspaceText (DivId, Text)
{ div = document.getElementById(DivId);
  txt = new String (Text)
  if (!div.name)
  { len = txt.length + 1;
  }
  else
  { len = parseInt(div.name);
  };
  div.name = len - 1;
  if (len > 1)
  { div.innerText = txt.substring (0, len - 1);
    toid = setTimeout ("BackspaceText('" + DivId + "', '" + Text + "')", TextDelay * 50);
  }
  else
  { div.innerText = "";
    div.name = "";
  };
};
function DeleteText (DivId, Text)
{ div = document.getElementById(DivId);
  txt = new String (Text)
  if (!div.name)
  { ind = 0;
  }
  else
  { ind = parseInt(div.name);
  };
  div.name = ind + 1;
  if (ind < txt.length)
  { div.innerText = txt.substring (ind, txt.length);
    toid = setTimeout ("DeleteText('" + DivId + "', '" + Text + "')", TextDelay * 50);
  }
  else
  { div.innerText = "";
    div.name = "";
  };
};
