/*
----------- FundSys.net(TM) Copyright SySys(R) Corp 2002 ------------
====================================================================
  Created By: WT
  Last Edited By: 
  Inception Date: 7/11/02
  Last Edited Date: 7/31/02
  Description:  None
  File Dependencies: 
    manage_dhtml_layer.js
===================================================================''*/

/*'''---------------------------------
'' initializeElementMove(element,offset,dropIn,hideTillScroll)
--------------------------------------
   Created By: WT
   Last Modified By:
   Compatibility: IE4+, NS4+
   Description: sets timeout to call function for element float, 
      place in top left or at top of any page you wish to have floating elements
   Parameters
     elmt: (str) ID of the element to float
     offset: (int)
     dropIn: (bool) true allows element to "drop in" from top of page, false for hidden until reaching offset
     hideTillScroll: (bool) true to keep element hidden until scroll (i.e. "Back to Top" button)
----------------------------------'''*/ 
//initialize variable
var topOffset = 0;

function initializeElementMove(element,offset,dropIn,hideTillScroll) { 
    window.setInterval("moveElement('" + element + "'," + offset + "," + dropIn + "," + hideTillScroll + ")",20); 
} 
 
/*'''---------------------------------
'' moveElement(elmt)
--------------------------------------
   Created By: WT (7/15/02)
   Last Modified By:
   Compatibility: IE4+, NS4+
   Description: floats element on page to specific offset
   Parameters
     elmt: (str) ID of the element to float
     offset: (int)
     dropIn: (bool) true allows element to "drop in" from top of page, false for hidden until reaching offset
     hideTillScroll: (bool) true to keep element hidden until scroll (i.e. "Back to Top" button)
----------------------------------'''*/ 
// !!! be careful with alert msgs in this function, as it is called every 20 milliseconds !!!
function moveElement(elmt,offset,dropIn,hideTillScroll) {
var str = '';
  topOffset = offset
  var style = (BD_is_nav4) ? '' : 'style.';    

  //hold element object in variable
  var elmObj = getElementObject(elmt);

  //get the position of the top of the scrollbar
  var scrollTop = BD_is_ie4up ? document.body.scrollTop : window.pageYOffset;

  //get absolute top of element -- function defined in manage_dhtml_layer.js
  //  NS6 has strange 9 pixel offset
  var elm_top = getAbsY(elmObj);

  //get the difference between the element's current top position and 
  //the position of where it should be relative to scroll position
  var diff = (scrollTop+topOffset)-elm_top;
    
  //weird NS deal, reset diff to zero if not a number
  if (isNaN(diff)) diff=0;
    
  //if the difference is positive, round result of difference * .1 up to next highest integer, if negative leave it alone
  if(diff > 0){
    if(BD_is_nav6up){
      eval('elmObj.' + style + 'top = "' + (elm_top + Math.ceil(.1*diff)) + 'px"');
    }else{
      (BD_is_nav4) ? elmObj.top += (.1*diff) : eval('elmObj.' + style + 'pixelTop += (Math.ceil(.1*diff))');
    }
  }else{
    if(BD_is_nav6up){
      // NS6 will move back to within 5 pixels of original position
      // this is a bug in the Math.round function for NS6 which won't round .5
      eval('elmObj.' + style + 'top = "' + (elm_top + (checkRound(.1*diff))) + 'px"');
    }else{
      (BD_is_nav4) ?  elmObj.top += (.1*diff) : eval('elmObj.' + style + 'pixelTop += (.1*diff)');
    }
  }

  //make element visible if it's reached initial position and param: dropIn is false
  if(!dropIn&&!hideTillScroll){
    if(getAbsY(elmObj) >= topOffset){
      showDIV(elmt);
    }
  }
  
  //allow element to "drop in" from top of page
  if(dropIn) showDIV(elmt);
  
  //keep item hidden until user scrolls
  if(hideTillScroll){
    (parseInt(scrollTop) == 0) ? hideDIV(elmt) : showDIV(elmt);
  }

//test block #######################
str += 'elm_top: ' + elm_top + '\n';
str += 'scrollTop: ' + scrollTop + '\n';
str += 'diff: ' + diff + '\n';
//document.frmTest.testtext.value = str;
//##################################

}//end moveElement


//PRIVATE 
//adjustment for bug in NS6 Math.ceil function
function checkRound(number){
  var newNumber = number
  if(Math.abs(number) <= 0.5) newNumber += .1;
  return newNumber;
}