var ie6orless = ie6orless || 0;
var agt = navigator.userAgent.toLowerCase();
var ie = (agt.indexOf("msie") != -1);

function syncFloatBoxToWScroll(boxId)
{
  var agt = navigator.userAgent.toLowerCase();
  var ie = (agt.indexOf("msie") != -1);

	var element = document.getElementById(boxId);
	var originalOffset = 250;
	var padding = 20;

	if (element)
	{
	  if (element.xfixed == undefined) element.xfixed = 0;
    var scrolled = false;
    if (ie)
      scrolled = (document.documentElement.scrollTop > (originalOffset-padding));
	  else
	    scrolled = (window.scrollY > (originalOffset-padding));

	  if (scrolled)
	  {
	    if (element.xfixed != 1)
	    {
	      element.xfixed = 1;
	      element.style.position = 'fixed';
	      if (ie6orless != undefined && (ie && (ie6orless == 1)))
	      {
	          //alert('scrolling on ie6 or less');
	          element.className = 'leftFixedFixedIe';
	          //element.className = 'leftFixedFixed';
	          //element.className = '';
	      }
	      else
	      {
	          //element.className = 'leftFixedFixed';
	           element.style.top = padding + 'px';
	      }
	    }
	  }
	  else
	  {
	    if (element.xfixed == 1)
	    {
	        //alert('scrolling off');
	      element.xfixed = 0;
	      element.style.position = 'absolute';
	      element.className = 'leftFixedFree';
	      element.style.top = originalOffset + 'px';
	    }
	  }

	}
}
	//window.setInterval('syncFloatBoxToWScroll("leftFixed")', 100);
function window_onscroll2()
{
  syncFloatBoxToWScroll("leftFixed");
}
function window_onscroll()
{
  var el = document.getElementById('leftFixed');
  if(el!=null)
  {
    if(typeof(document.media)=='string')
    {// only do this for ie
      var s;
      // scrolling offset calculation via www.quirksmode.org
      if (self.pageYOffset)
      {
        s = self.pageYOffset;
      }
      else if (document.documentElement && document.documentElement.scrollTop)
      {
        s = document.documentElement.scrollTop;
      }
      else if (document.body)
      {
        s = document.body.scrollTop;
      }
      el.style.top= s + 30;

    }

    if(typeof(window.print)=='function')
    {// only do if not ie
      var x;
      // scrolling offset calculation via www.quirksmode.org
      if (self.pageXOffset)
      {
        x = self.pageXOffset;
      }
      else if (document.documentElement && document.documentElement.scrollTop)
      {
        x = document.documentElement.scrollLeft;
      }
      else if (document.body)
      {
        x = document.body.scrollLeft;
      }
      el.style.left = (548 - x) + "px";
    }
  }
}

if (ie6orless == 1)
{
    window.setInterval('syncFloatBoxToWScroll("leftFixed")', 100);
}
else
{
  window.onscroll = window_onscroll2;
}
