
/*
 ***********************MOVE Sequences Library*******************************
 *
 * Predefine Movement Sequences - then perform animation when you want it 
 *
 * Free for all users, but leave in this  header
 * Author: Sally Ferreira, contact thru web site @
 *          www.stormloaders.com/4colors
 *
 * Setup: Encase move items in DIVs
 *        Enter move info into move_list array
 *        call move_init() upon page load
 *        call move_now(ix[,ix2 ..]) to activate animation(s) 
 *                     where ix = move_list index number(s)
 *
 * Place an array called move_list in your HTML and define your move sequences               
 * in string variables containing parameters in this order:
 *
 *   div id name, Xstart, Xstop, Ystart, Ystop, Max pixels moved per Step,
 *   Speed in milliseconds, Reset flag (1= move back to 1st X,Y pos at move end) 
 *                
 * Ex:     move_list = new Array() 
 *         move_list[0] = "mydiv,-100,340,340,-100,5,30,0"  (diagonal move)
 *         move_list[1] = "div3,400,40,10,10,14,70,0"       (horizontal move)
 *         move_list[2] = "ss1,115,115,0,300,8,18,0"        (vertical move)
 *         move_list[3] = "ss1,500,222,59,177,10,20,1"      (freeform move + reset)
 *  
 *                             ... onmouseover="move_now(3,1,0)"  
 *             
 ***************************************************************************
*/
function move_init() {
 mVobj = new Object() ;
 var brw , i 
 //insure browser type is known 0=IE,1=NS4,2=NS6
 if (document.all) brw = 0
 else if (document.layers) brw = 1
 else if (document.getElementById) brw = 2
 else brw = 3
 for (i=0; i< move_list.length; i++) 
   move_item[i]=new makemVObj(i,brw) 
 }
function move_now() {
 var j
 var i = 0 ;
 while (i < move_now.arguments.length) {
  j= move_now.arguments[i]
  if (j < move_list.length){move_item[j].mVnow()}
  i++
  }
}
move_item = new Array() ;
function mVput() {
  this.ref.top=this.ys
  this.ref.left=this.xs
  }
function mVnow() {
 if (this.status < 0) return         //error?
 mVobj[this.mVid].mVput()            //update position

 //end of move sequence?
 if (this.xs == this.xq && this.ys == this.yq){ 
    this.xs = this.xreset; this.ys = this.yreset;
    if (this.status == 1) mVobj[this.mVid].mVput() //really should have time delay here
    return
   }
 //incr/decr positions - dont go too far
 this.xs += this.xi ; this.ys += this.yi
 if (this.xi < 0) {if (this.xs < this.xq) this.xs = this.xq}
 else if (this.xi > 0) {if (this.xs > this.xq) this.xs = this.xq}
 if (this.yi < 0) {if (this.ys < this.yq) this.ys = this.yq}
 else if (this.yi > 0) {if (this.ys > this.yq) this.ys = this.yq}
 setTimeout('mVobj["'+ this.mVid + '"].mVnow()',this.speed)
  } 
function mVrange(first,last){
 var range, negl

//check for large negative numbers which affect timing
 if (first < 0) {neg1 = first * -1 ; first = 0}
 else neg1 = 0
 if (last < 0) {neg1 += (last * -1) ; last = 0}
 if (first < last) range = last - first
 else range = first - last
 range += neg1 
 return range
 }
/*
 * register move sequence - make move_list item an object
 * which points to (divid,xstart,xstop,ystart,ystop,step,speed,reset)
*/
function makemVObj(which,bw){
       var xr, yr, xdir, ydir,z1, zx, zy, i
       var error = 0
// p/u parms, error check, set defaults 
 var p = new Array(0,0,0,0,0,5,20,0)
 var parms=move_list[which].split(",")
 var divid = "" + parms[0]
 for (i=1; i< parms.length ;i++){ p[i] = parseInt(parms[i],10) }
 if (p[1] < 0 && p[2] < 0) error = 1      // from/to both negative?
 if (p[3] < 0 && p[4] < 0) error = 1
 if (p[5] < 0) p[5] *= -1                 //insure positive step value
 if (p[5] == 0) p[5] = 1                  //no endless loops 
 if (p[6] < 0) p[6] *= -1                 //insure positive delay value
 this.xreset = p[1]                       //reset for x
 this.yreset = p[3]                       //reset for y
 this.status = p[7]                       //reset desired?

// get move range sizes, determine step directions
// try to decrease step size for shorter move leg
 xr = mVrange(p[1],p[2]) ; xy = mVrange(p[3],p[4])
 if (p[2] < p[1]) xdir = -1
 else  xdir = 1
 if (p[4] < p[3]) ydir = -1
 else  ydir = 1
 zx = zy = p[5]                                
 if (yr > xr) {z1 = Math.round(yr/zx); zx=Math.round(xr/z1)}
 else if (xr > yr) { z1 = Math.round(xr/zy); zy=Math.round(yr/z1)}

//bw is browser type - 0=IE, 1=NS4, 2=NS6
 if (bw == 0) this.ref=document.all[divid].style                    
 else if (bw == 1) this.ref=document[divid]                        
 else if (bw == 2) this.ref=document.getElementById(divid).style   
 else error = 1

 this.xs = p[1]                //xstart
 this.xq = p[2]                //xstop 
 this.xi = zx * xdir           //xstep 
 this.ys = p[3]                //ystart
 this.yq = p[4]                //ystop
 this.yi = zy * ydir           //ystep
 this.speed = p[6]             //delay time
 this.mVid = which             //identify by index
 if (error != 0)               
   this.status = -1            //dont process this one           
 this.mVput = mVput 
 this.mVnow = mVnow 
 mVobj[which] = this;  
 }
/* ******************End MOVE Sequences Library******************************* */
//
