//      [DynamicMovement v1.2]
//
//              date: 10/26/98
//
//      This script ables you to easily move
//      objects dynamically around the screen.
//
//  NEW! for version 1.2:
//
//  Cross-browser functionality, the script
//  now delivers DynamicMovement to both
//  MSIE 4.x and Netscape 4.x
//
//  Commercial use prohibited.
//
//      (C) Copyright Jari Aarniala, 1998
//              [foo@dlc.fi - www.dlc.fi/~foo]
//
//  Date: 2/22/7
//  Modified to allow for resizing of object to simulate depth of page.

IE4 = navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) >= 4;
NS5 = ((navigator.userAgent.indexOf("Gecko")>-1) && dom) ? true: false;

// checkBrowser() -- Checks whether the browser is new enough for some DynamicMovement ...

function checkBrowser()
{
    if(IE4 || NS5)
    {
        return true;
    }
    return false;
}

// movableObj() -- Creates a new movable object

function movableObj(startX, startY, endX, endY, startH, startW, endH, endW, delay, speed, refId, picRefId)
{
    this.sX = startX;
    this.sY = startY;
    this.eX = endX;
    this.eY = endY;
    this.sW = startW;
    this.sH = startH;
    this.eW = endW;
    this.eH = endH;
    this.de = delay;
    this.sp = speed;
    this.ref = refId;
    this.picRef = picRefId;
    this.WS = 0;
    this.HS = 0;
    xL = endX - startX;
    yL = endY - startY;
    with (Math)
    {
        if(abs(xL) > abs(yL))
        {
            this.xS = (xL > 0)?1:-1;
            this.yS = (yL > 0)?abs(yL / xL):-abs(yL / xL);
            this.howManySteps = abs(xL / speed);
        }
        else if(abs(yL) > abs(xL))
        {
            this.yS = (yL > 0)?1:-1;
            this.xS = (xL > 0)?abs(xL / yL):-abs(xL / yL);
            this.howManySteps = abs(yL / speed);
        }
        else
        {
            this.yS = (yL > 0)?1:-1;
            this.xS = (xL > 0)?1:-1;
            this.howManySteps = abs(xL / speed);
        }
    }
    this.startMovement = startMovement;
    this.WS = (startW-endW)/this.howManySteps;
    this.HS = (startH-endH)/this.howManySteps;
}

// startMovement() -- starts the movement

function startMovement()
{
    if(checkBrowser())
    {
        ref = document.getElementById(this.ref);
        picRef = document.getElementById(this.picRef);
        doDynamicMovement(this.sX, this.sY, this.eX, this.eY, this.sH, this.sW, this.eH, this.eW, this.de, this.xS, this.yS, this.HS, this.WS, ref, picRef, this.sp, this.howManySteps);
    }
}

// doDynamicMovement() -- does the Dynamic Movement

function doDynamicMovement(curX, curY, eX, eY, curH, curW, eH, eW, sp, xS, yS, HS, WS, ref, picRef, speed, hS)
{
    if(Math.floor(hS - 1) != 0)
    {
        hS--;
        curX += xS * speed;
        curY += yS * speed;
        curH -= HS;
        curW -= WS;
        ref.style.left = Math.round(curX);
        ref.style.top = Math.round(curY);
        picRef.style.height = Math.round(curH);
        picRef.style.width = Math.round(curW);

        setTimeout("doDynamicMovement(" + curX + ", " + curY + ", " + eX + ", " + eY + ", " + curH + ", " + curW + ", " + eH + ", " + eW + ", " + sp + ", " + xS + ", " + yS + ", " + HS + ", " + WS + ", ref, picRef, " + speed + ", " + hS + ")", sp);
    }
    else
    {
        setPos(eX, eY, eH, eW, ref, picRef);		if (!securityPatrol)			hideMessage();
    }
}

// setPos() -- sets the end position accurately when doDynamicMovement has done its job

function setPos(x, y, h, w, ref, picRef)
{
    ref.style.left = x;
    ref.style.top = y;
    picRef.style.height = h;
    picRef.style.width = w;

    objectInMotion = false;
}

