

// mouse move
var xmouse = 0;
var ymouse = 0;


if (navigator.appName == 'Netscape') {
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = netscapeMouseMove;
}

function netscapeMouseMove(e) {
    if (e.screenX != xmouse && e.screenY != ymouse) {
        xmouse = e.screenX;
       ymouse = e.screenY;
    } 
}



function microsoftMouseMove() {
    if (window.event.x != document.test.x.value && window.event.y != document.test.y.value) {
        xmouse = window.event.x;
        ymouse = window.event.y;
    }
}

// BODY onMousemove="microsoftMouseMove()"
// end mouse move



var the_timeout;

var the_coords = new Array("700:42","710:42","685:42","250:42","350:42","50:42","190:42","380:42","250:42","30:42","500:42","800:42","380:42","700:42");

var old_position;
var last_xmouse = 0;
var following_mouse;
var mouse_counter;

// function getAnchors()
//    this function gets the two anchor points of a segment
//    of the path and then calls moveDiv() to move the 
//    DIV along that segment
//
function getAnchors(array_position, start)
{

// restarting stopped caravan
if (!the_timeout && start && old_position){

if(old_position < the_coords.length){
array_position = old_position + 1;
}
//alert("old_position: " + old_position);
}


// click while running to stop
if (the_timeout && start){

clearTimeout(the_timeout);
the_timeout = '';
return(false);

} else {

old_position = array_position;

  var first_anchor = the_coords[array_position];
  var second_anchor = the_coords[array_position+1];


  array_position++;
  if (array_position == the_coords.length-1)
  {
    array_position = 0;
  }


  moveDiv(array_position, first_anchor, second_anchor, 0, 0);


}


}


// function moveDiv()
//   this function moves the DIV along a segment of the path
//   based on the anchor points.  It will keep calling 
//   itself with a setTimeout() until the DIV is at the end 
//   of the segment
//
function moveDiv(array_position, anchor_one, anchor_two, 
                       horizontal_step_size, vertical_step_size)
{
  var the_style = getStyleObject("myDiv");
  if (the_style)
  {

    // get the first anchor
    //    
    var first_points = anchor_one.split(":");
    var first_left = parseInt(first_points[0]);
    var first_top = parseInt(first_points[1]);



    // get the second anchor
    //
    var second_points = anchor_two.split(":");
    var second_left = parseInt(second_points[0]);
    var second_top = parseInt(second_points[1]);

    // if we don't know the step sizes to move the DIV, figure them out
    //
    if ((horizontal_step_size == 0) && (vertical_step_size == 0))
    {
      horizontal_step_size = 
        getStepSize(anchor_one, anchor_two, 0);

//     vertical_step_size = 
//       getStepSize(anchor_one, anchor_two, 1);
vertical_step_size = 0;

   }


    // figure out the new coordinates
    //
    var new_left = first_left + horizontal_step_size;
    var new_top = first_top + vertical_step_size;


    // if we're at the end of the segment, set the coordinates to
    // move the DIV to the end
    //
    if (atEndOfPath(horizontal_step_size, second_left, new_left) 
       ||(atEndOfPath(vertical_step_size, second_top, new_top)))
    {
      new_left = second_left;
      new_top = second_top;
    }

    // add the px or don't, depending on the browser
    if (!document.layers) 
    {
      new_left = new_left + "px";
      new_top = new_top + "px";
    }

    // now actually move the DIV
    //
    the_style.left = new_left;
    the_style.top = new_top;
    
    
    // if we're at the end of the segment, get new anchors
    // otherwise, call moveDiv() again with a new starting point
    // along the segment
    //
    if ((parseInt(new_left) == parseInt(second_left)) && 
            (parseInt(new_top) == parseInt(second_top)))
    {
    
    if (following_mouse && mouse_counter < 6){
    var mouse_left = Math.abs( (parseInt(new_left) + 300 ) - parseInt(new_left));
    anchor_two = mouse_left + ":42";
    mouse_counter++;
    
    
   // alert("new anchor_two: " + anchor_two);
 //      window.moveBy(1, 0);
       
//       shake_xy(3);
       //quake();
       
    moveDiv(0, parseInt(new_left) + ":42", anchor_two, 0, 0);
    

    } else {
    
      getAnchors(array_position);
      following_mouse = false;
     //  alert("new from array, reached: " + new_left);
       }
    } 
    else 
    {
      var new_anchor_one = new_left + ":" + new_top;


// follow mouse
if (ymouse < 200 && (Math.abs(xmouse - last_xmouse) > 3) ){ //&& xmouse > 0
//var newx = xmouse - 100;
anchor_two = (xmouse - 150) + ":42";
//  anchor_two = xmouse  + ":42";
 horizontal_step_size = 0;
 vertical_step_size = 0;
 last_xmouse = xmouse;
 following_mouse = true;
 mouse_counter = 1;
} 




      var timeout_string = "moveDiv(" +
        array_position + ", '" + new_anchor_one + "', '" +
        anchor_two + "', " + horizontal_step_size + "," + 
        vertical_step_size + ");";

      the_timeout = setTimeout(timeout_string, 100);
    }
  }
}





// function getStepSize()
//  this figures out how much to move the DIV each time
//
function getStepSize(anchor_one, anchor_two, position)
{

  var first_points = anchor_one.split(":");
  var first_number = parseInt(first_points[position]);

  var second_points  = anchor_two.split(":");
  var second_number = parseInt(second_points[position]);

  var step_size = Math.round((second_number - first_number)/30);

if ( (step_size < 1 && step_size > 0) || step_size == 0){
step_size = 1;
}
if (step_size > -1 && step_size < 0){
step_size = -1;
}

//alert(step_size);

  return step_size;
}

// function atEndOfPath()
//   if the DIV is about to be moved past the end point of
//   the segment, this will return true.  Otherwise, it will
//   return false.
//
function atEndOfPath(the_step_size, second_number, new_number)
{
    var the_end = false;

    if (((the_step_size > 0) && (new_number > second_number)) ||
        ((the_step_size < 0) && (new_number < second_number)))
   {
     the_end = true;
   }

   return the_end;
}


function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject





/*
// shake

var qDuration=600; 
var qCounter=0; 

function quake() { // the horizontal displacement 
var deltaX=1; // make sure the browser support the moveBy method 

if (window.moveBy) { 

for (qCounter=0; qCounter<qDuration; qCounter++) { // shake left 

if ((qCounter%4)==0) { window.moveBy(deltaX, 0); } // shake right else 

if ((qCounter%4)==2) { 
window.moveBy(-deltaX, 0); 
} // speed up or slow down every X cycles

if ((qCounter%30)==0) { // speed up halfway 
if (qCounter<qDuration/2) { 
deltaX++; 
} // slow down after halfway of the duration 
else { 
deltaX--; 
} 

} 
} 
} 
} 
*/

function shake_xy(n) {
if (self.moveBy) {
for (i = 10; i > 0; i--) {
for (j = n; j > 0; j--) {
self.moveBy(0,i);
self.moveBy(i,0);
self.moveBy(0,-i);
self.moveBy(-i,0);
}
}
}
}
function shake_x(n) {
if (self.moveBy) {
for (i = 10; i > 0; i--) {
for (j = n; j > 0; j--) {
self.moveBy(i,0);
self.moveBy(-i,0);
}
}
}
}
function shake_y(n) {
if (self.moveBy) {
for (i = 10; i > 0; i--) {
for (j = n; j > 0; j--) {
self.moveBy(0,i);
self.moveBy(0,-i);
}
}
}
}



