/*
Floating Menu script - floats a <div> element within another element with fixed x offset,
while the y offset tracks the vertical scrolling of the page.
- based on Roy Whittle's script (http://www.javascript-fx.com/)
Modified to work within a <div> element anywhere on the page.
*/
if (!document.layers){
  document.write('</div>');
}

function floatTopLeft()
{
  var isNetscape = (navigator.appName.indexOf("Netscape") != -1);
  var doc = document;
  var container = doc.getElementById("container");
  var startX = findPosX(container) + 6;
  var startY = findPosY(container) + 160;

  function moveLayer(id)
  {
    var element=doc.getElementById?doc.getElementById(id):doc.all?doc.all[id]:doc.layers[id];
    if(doc.layers){
      element.style = element;
    }
    element.startPos=function(x,y){
      this.style.left = x;
      this.style.top = y;
    };
    element.x = startX;
    element.y = startY;
    return element;
  }
  
  window.stayTopLeft=function()
  {
    var pageY = isNetscape ? pageYOffset : document.body.scrollTop;
    floatTopLeftObj.y += (pageY + startY - floatTopLeftObj.y)/8;
    floatTopLeftObj.startPos(floatTopLeftObj.x, floatTopLeftObj.y);
    setTimeout("stayTopLeft()", 10);
  }
  
  floatTopLeftObj = moveLayer("divStayTopLeft");
  stayTopLeft();
}

floatTopLeft();

//Reset position when onresize event triggered: support the onresize event for different browsers.
document.body.onresize = function() {
  floatTopLeft();
}

self.onresize = function() {
  floatTopLeft();
}

function findPosX(obj){
  var curleft = 0;
  if(obj.offsetParent){
    while(1) {
      curleft += obj.offsetLeft;
      if(!obj.offsetParent){
        break;
      }
      obj = obj.offsetParent;
    }
  } else if(obj.x) {
    curleft += obj.x;
  }
  return curleft;
}

function findPosY(obj){
  var curtop = 0;
  if(obj.offsetParent){
    while(1){
      curtop += obj.offsetTop;
      if(!obj.offsetParent){
        break;
      }
      obj = obj.offsetParent;
    }
  } else if(obj.y) {
    curtop += obj.y;
  }
  return curtop;
}
  
