var xstop=0;
var ystop=0;
var speedms=100;
var xstep=20;
var ystep=5

function RotatorOnStartFlying(rotatorId, viewerWidth, viewerHeight){
	// this function gets called when the 3DRotator Viewer has loaded and is ready.
 
	if (document.getElementById){
		 RotatorViewerNamed[rotatorId] = document.getElementById(rotatorId);

		// now JavaScript anywhere on your page can test to see if the Rotator Viewer has finished loading with a line like this
		if (RotatorViewerNamed[rotatorId] != null){
			// Viewer has finished loading
			// do something
	
			//RotatorFlying(rotatorId, targetx, targety, speedmilliseconds, stepsizex, stepsizey)
			RotatorFlying(rotatorId, xstop, ystop, speedms, xstep, ystep);

		}else{
			// Viewer has NOT finished loading yet
			// do something different
		}
 	} // end if document.getElementById

} // end function RotatorOnStartFlying



function RotatorFlying(rotatorId, targetx, targety, speedmilliseconds, stepsizex, stepsizey){
// you must put the viewer inside <DIV id='DIVRotatorViewer"></DIV> tags


// everytime this function is called, step one position closer to target


if (RotatorViewerNamed[rotatorId] != null){

   // get the DIV id
	var destinationLink = null;
	var myDiv = document.getElementById("DIV" + rotatorId);
	var divs = document.getElementsByTagName('div');
	for (var offset = 0; offset < divs.length; offset++) {
	  if (divs.item(offset) == myDiv){
	   	destinationLink = divs.item(offset);
	 	break; 
		}
	 }
 
  // find current position of DIV that viewer is in
	var currentx;
	var currenty;
	if (destinationLink){
	 	 currentx = destinationLink.offsetLeft;  
		  currenty = destinationLink.offsetTop;   
		 var thisNode = destinationLink; 
		 while (thisNode.offsetParent &&  
		       (thisNode.offsetParent != document.body)) { 
			   thisNode = thisNode.offsetParent; 
			   currentx += thisNode.offsetLeft; 
			   currenty += thisNode.offsetTop; 
		}
	}else{ 
	// table name not found so default to target positions so this function stops calling itself
		currentx = targetx;
		currenty = targety;
	}
 

  // move DIV one step closer to target
	var nextpositionx; 
	var nextpositiony;


	if (Math.abs(eval(targetx) - eval(currentx)) < eval(stepsizex)){ // less than a step so jump right there
		nextpositionx = eval(targetx);
	}else{// take a step closer
		if (eval(currentx) < eval(targetx)){
		nextpositionx = eval(currentx) + eval(stepsizex);
		}else{
		nextpositionx = eval(currentx) - eval(stepsizex);
		}
	} // end if room to take a step in x

	if (Math.abs(eval(targety) - eval(currenty)) < eval(stepsizey)){ // less than a step so jump right there
		nextpositiony = eval(targety);
	}else{// take a step closer
		if (eval(currenty) < eval(targety)){
		nextpositiony = eval(currenty) + eval(stepsizey);
		}else{
		nextpositiony = eval(currenty) - eval(stepsizey);
		}
	} // end if room to take a step in y



	destinationLink.style.left = nextpositionx + "px";
	destinationLink.style.top = nextpositiony + "px";

//	destinationLink.innerHTML = "currentx:" + currentx + "currenty:" + currenty  + " -- nextx:" + nextpositionx + ":nexty:" + nextpositiony+ " -- targetx:" + targetx + ":targety:" + targety;



 


 


   //if not yet reached target call this function again in speedmilliseconds
	if ((targetx != currentx) || (targety != currenty)){
	setTimeout( 'RotatorFlying("' + rotatorId +'","' + targetx +'","' + targety +'","' + speedmilliseconds +'","' + stepsizex +'","' + stepsizey +'");' ,speedmilliseconds); 
	}

} // end if viewer loaded




} // end function RotatorFlying






function RotatorJumpTo(rotatorId, targetx, targety){
// you must put the viewer inside <DIV id='DIVRotatorViewer"></DIV> tags


   // get the DIV id
	var destinationLink = null;
	var myDiv = document.getElementById("DIV" + rotatorId);
	var divs = document.getElementsByTagName('div');
	for (var offset = 0; offset < divs.length; offset++) {
	  if (divs.item(offset) == myDiv){
	   	destinationLink = divs.item(offset);
	 	break; 
		}
	 }
 
 
	destinationLink.style.left = targetx + "px";
	destinationLink.style.top = targety + "px";


} // end function RotatorJumpTo
