﻿/* Java animation
The arrays allow move to occur without interferring with one another

*/

var gas = new Array();
var pos = new Array();
var DEND = new Array();
var DHGT = new Array();
var DLeft = new Array();
var DTop = new Array();
var DW = new Array();
var DH = new Array();
var PW = new Array();
var PH = new Array();
var STRT = new Array();
var mtop = new Array();
var P;
var tm = new Array();
var DX;
var DY;
var DestTop = new Array();
var DestLeft = new Array();
var DestWidth = new Array();
var D;
var stmt = 'void(0)'
var FRAMES = new Array();
var LFT = new Array();
var HGT = new Array();
var TP = new Array();
var WDT = new Array();
var ELEM = document.getElementsByTagName('img');
var IDX = new Array();
var tma = new Array();
var i;
var xx = new Array();

//Save original sizes and locations
for(i=0; i<ELEM.length; i++)
    {
    var E = ELEM[i];      
    if (E.id != '')
        {
        IDX[i] = E.id;
        LFT[i] = E.style.left; 
        TP[i] = E.style.top; 
        HGT[i] = E.height; 
        WDT[i] = E.width;     
         } 
    } 

//Reset sizes and location to original
function Reset()
    {  
    for(i=0; i<LFT.length; i++)
        {
        var E = ELEM[i]; 
        if(E.id != '')
            {
            var EL = document.getElementById(E.id);
             if(EL.height){EL.height = HGT[i]}
             if(EL.width){EL.width = WDT[i]}
            if(EL.style)
                    {
                     EL.style.left = LFT[i];
                     EL.style.top = TP[i];
                     EL.style.height = HGT[i];
                     EL.style.width = WDT[i];
                     EL.style.visibility = 'hidden';                     
                    }
             }
         }       
     }
      
function jmove(GIF,DIR,DEST,STEPS) 
    {
    /* First find the table location of the image */ 
     var i; 
     for( i=0;i<ELEM.length;i++)
        {
         var E = ELEM[i];
         if(E.id == GIF){break};
         }
   /*set the parameters D=destination, P=Source, DIR=type of effect */
    if (document.body.leftMargin)
        { 
        var OffsetLeft = Number(document.body.leftMargin);
        var OffsetTop = Number(document.body.topMargin);
        }else{
        var OffsetLeft = Number(document.getElementById('pageOffsetLeft').value);
        var OffsetTop = Number(document.getElementById('pageOffsetTop').value);
        }
    FRAMES[i] = STEPS;
    gas[i] = STEPS; 
    D =  document.getElementById(DEST);   //destination
    DH[i] = Number(D.height);    //height of destination   
    P = document.getElementById(GIF);        //Source object element
    DTop[i] =  Number(D.offsetTop);
    DLeft[i] = Number(D.offsetLeft); 
    DestTop[i] = DTop[i] + Number(OffsetTop);   //top of destination with page offset
    DestLeft[i] = DLeft[i] + Number(OffsetLeft);   //left of destination with page offset
    pos[i] = DestTop[i] + DH[i];   //bottom of destination
    P.style.top = pos[i];        //top of source
    P.style.left = DestLeft[i] + OffsetLeft;   //left of source with page offset
    P.style.visibility = 'visible'; 
    DEND[i] = DestTop[i];
    DestWidth[i] = D.width;
    DHGT[i] = P.height;
    DW[i] = P.width;
    PW[i] = P.width;                       //width of destination
    mtop[i] = pos[i];
    STRT[i] = mtop[i];
    /* identify the command and set the parameters */
    if(DIR == "scrollup"){scrollup(i)}
    if(DIR == "zoomin")
        {
        DEND[i] = screen.height;
        zoomin(i);
        } 
    if(DIR == "scrolldown")
        {
        P.style.top = DestTop[i] - DH[i];
        DEND[i] = DestTop[i]; 
        pos[i] = DestTop[i] - DH[i];
        mtop[i] = pos[i];      
        scrolldown(i);
        }
    if(DIR == "swingup")
        {  
        P.height = 1; 
        mtop[i]=1; 
        pos[i]=1; 
        swingup(i); 
        }
    if(DIR == "swingdown")
        {          
        P.height = 1; 
        P.style.top = DestTop[i];
        STRT[i] = DestTop[i]; 
        mtop[i] = 1;
        swingdown(i); 
        }
    if(DIR == 'swingright')
        {
        P.width = 1;
        P.style.top = DestTop[i];
        mtop[i] = 1;
        swingright(i);       
        }
    if(DIR == 'swingleft')
        {
        P.width = 1;
        P.style.top = DestTop[i];
        P.style.left = DestLeft[i] + PW[i];
        mtop[i] = 1;        
        swingleft(i);       
        }
    if(DIR == 'incomingse')
        {
         PH[i] = P.height;
         P.style.left = 800;
         P.style.top = 800;
         P.style.width = P.width/3;
         P.style.height = P.height/3 ;
         DX = P.style.left.slice(0,-2) - Number(D.offsetLeft);
         DY = P.style.top.slice(0,-2) - Number(D.offsetTop);
         svgas = gas[i];
         tmc = 0;
         XX = DX;
         if(DY > DX){XX = DY}
         gas[i] = (Math.round(XX / FRAMES[i]));
         xx[i] = 0;
         stmt = "gas[" + i + "] = svgas; mtop[" + i + "] = 1; var P = document.getElementById(IDX[" + i + "]);  P.style.height = PH[" + i + "]; P.style.width = 10; swingright(" + i + ")";
         incomingse(i);
        } 
    if(DIR == 'moveleft')
        {
         PH[i] = P.height;
         P.style.left = DestLeft[i] + DestWidth[i];
         P.style.top = DestTop[i];
         DX = P.style.left.slice(0,-2) - Number(D.offsetLeft);
         DY = P.style.top.slice(0,-2) - Number(D.offsetTop);
         svgas = gas[i];
         tmc = 0;
         XX = DX;
         if(DY > DX){XX = DY}
         gas[i] = (Math.round(XX / FRAMES[i]));
         xx[i] = 0;
         incomingse(i);
        } 
    }
function incomingse(i) 
    {   
     if(xx[i]  > FRAMES[i]){eval(stmt);return true}
     xx[i]++;
     var P = document.getElementById(IDX[i]);
     DX = Number(P.style.left.slice(0,-2));
     DY = Number(P.style.top.slice(0,-2));
     /*
     document.getElementById('DEST').value = DLeft[i] + '   ' + DTop[i];
     document.getElementById('SRC').value = P.style.left + '   ' + P.style.top;
     document.getElementById('CALC').value = DY + ' ' + DX;
     */
     DX = DX - gas[i];
     DY = DY - gas[i];
     if( DY <= DTop[i]){DY = DTop[i]} 
     if( DX <= DLeft[i]){DX = DLeft[i]}
     P.style.left = DX;
     P.style.top = DY; 
     tm[i] = setTimeout("incomingse(" + i + ")",10);
    }    
function swingup(i)
    {
     mtop[i] = mtop[i] + gas[i];
     var P = document.getElementById(IDX[i]);
     if(mtop[i] > DHGT[i]){mtop[i] = DHGT[i];stopmove();return true}
    P.height = mtop[i];  
    P.style.top =  STRT[i] - mtop[i]; 
    tm[i] = setTimeout('swingup(' + i + ')',1);
    }    
function swingdown(i)
    {
     mtop[i] = mtop[i] + gas[i];
     var P = document.getElementById(IDX[i]);
     if(mtop[i] > DHGT[i]){mtop[i] = DHGT[i];stopmove(i);return true}
     P.height = mtop[i];  
     P.style.top =  STRT[i];
     tm[i] = setTimeout('swingdown(' + i + ')',1);
     }     
function swingright(i)
    {
     mtop[i] = mtop[i] + gas[i];
     var P = document.getElementById(IDX[i]);
     if(mtop[i] > DW[i]){P.style.width = DW[i];stopmove(i);return true}
     P.style.width = mtop[i]; 
     tm[i] = setTimeout('swingright(' + i + ')',10);
    }  
function swingleft(i)
    {
	var pl = Number(P.style.left.slice(0,-2));
    var P = document.getElementById(IDX[i]);
	mtop[i] = mtop[i] + gas[i];
    if(mtop[i] > PW[i]){P.style.width = PW[i];stopmove(i);return true}
    P.style.width = mtop[i];
    P.style.left = pl - mtop[i]; 
    tm[i] = setTimeout('swingleft(' + i + ')',10);
    }  
function scrollup(i)
    {
     pos[i] = pos[i] - gas[i];
     var P = document.getElementById(IDX[i]);
     if(pos[i] < DEND[i]){pos[i] = DEND[i];stopmove(i);return true}
     mtop[i] = mtop[i] - gas[i];  
     P.style.top = mtop[i];        
     tm[i] = setTimeout('scrollup(' + i + ')',1);
    }  
function scrolldown(i)
    {
     pos[i] = pos[i] + gas[i];
     var P = document.getElementById(IDX[i]);
     if(pos[i] > DEND[i]){pos[i] = DEND[i];stopmove(i);return true}
    mtop[i] = mtop[i] + gas[i];   
    P.style.top = mtop[i];
    tm[i] = setTimeout('scrolldown(' + i + ')',1);
    } 
function zoomin(i)
    {
     var P = document.getElementById(IDX[i]);
     P.width = P.width * 1.1;
     P.height = P.height * 1.1;
     if(Number(P.height) >= Number(DEND[i])){stopmove(i);return true}
    tm[i] = setTimeout('zoomin(' + i + ')',1);       
    }       
function stopmove(i)
    {
    clearTimeout(tm[i]);
    }

var exe = new Array(); 

var done;  
