FloatedLayer = false;
FloatMargin = false;

function floatLayer(id)
  {
    window.setTimeout("floatLayerDelayed('" + id + "')", 500);
  }

function floatLayerDelayed(id)
  {
    FloatedLayer = document.getElementById(id);
    var el = FloatedLayer;
  	var y=-2;
  	while(el){
  		y+=el.offsetTop;
  		el=el.offsetParent;
  	}
  	FloatMargin = y;

    var el = FloatedLayer;
 		x=0;
    while(el){
	   	x+=el.offsetLeft;
		  el=el.offsetParent;
	  }

    var el = FloatedLayer;

  	//el.style.position='absolute';
		//el.style.top=y;
	  //el.style.left=x+1;

    setInterval(checkMoving, 20);
    setInterval(adjustLayer, 200);
  }

function getScroll()
  {
    if (document.documentElement && !document.documentElement.scrollTop)
      // IE6 +4.01 but no scrolling going on
      return 0;
    else if (document.documentElement && document.documentElement.scrollTop)
      // IE6 +4.01 and user has scrolled
      return document.documentElement.scrollTop;
    else if (document.body && document.body.scrollTop)
      // IE5 or DTD 3.2
      return document.body.scrollTop;
  }

isMoving = 0;
LastScroll = 0;
function checkMoving()
  {
    var scroll = getScroll();
    if (LastScroll!=scroll)
      {
        isMoving++;
        LastScroll = scroll;
      }
  }

function adjustLayer()
  {
    if (isMoving>0)
      {
        isMoving = 0;
        return;
      }

    var scroll = getScroll();
    if (scroll)
  		 FloatedLayer.style.borderTop="1px solid #006699";
  	else
  	   FloatedLayer.style.borderTop="none";
    if (scroll <=  FloatMargin)
         new Effect.Move(FloatedLayer,{x:0, y: 0, mode: 'absolute', fps: 50, duration: 0});
    else
         new Effect.Move(FloatedLayer,{x:0, y: scroll-FloatMargin, mode: 'absolute', fps: 50, duration: 0});
  }



