var target_x = -270;
var target_y = 0;
var nMenuYPos = 120;
var DocHeight=0;
var bottomStop;
var has_inner = typeof(window.innerWidth) == 'number';
var has_element = document.documentElement && document.documentElement.clientWidth;
		 

var fm_id='floatdiv';
var floating_menu =
    document.getElementById
    ? document.getElementById(fm_id)
    : document.all
      ? document.all[fm_id]
      : document.layers[fm_id];

var fm_shift_x, fm_shift_y, fm_next_x, fm_next_y;

function getFirstDivTop()
{	

	return document.getElementById("floatdiv").offsetHeight+10;
}

function setLeftStartPos(topTable,floatName,isFloating)
{
	nMenuYPos=findPosY(document.getElementById(topTable));
	fm_id=floatName;
	
	
	
	floating_menu =
    document.getElementById
    ? document.getElementById(fm_id)
    : document.all
      ? document.all[fm_id]
      : document.layers[fm_id];
	
	leftPoint=document.getElementById(topTable).offsetWidth+findPosX(document.getElementById(topTable));
	
	extraDivStartY=0;
	if(floatName=="floatdiv2")
	{
		extraDivStartY= getFirstDivTop();
	}
	if (document.layers)
    {
        floating_menu.left = leftPoint + xDelta + 'px;';
		floating_menu.top = extraDivStartY + nMenuYPos + 'px;';			
    }
    else
    {
        floating_menu.style.left = leftPoint + xDelta;        
		floating_menu.style.top = extraDivStartY + nMenuYPos;		
    }
	
	
	
	if (document.height) DocHeight = document.height;
	else 
		if (document.body.scrollHeight) 
			{
				DocHeight = document.body.scrollHeight;
			}
			else
			{
				DocHeight = document.documentElement.scrollHeight;
			}	
	bottomStop=findPosY(document.getElementById('bottomTable'));	
	
	
	
	
	if(isFloating=="float")
		{
			compute_shifts();
			if (document.layers)
			{
				fm_next_y = 0;
			}
			else
			{
				fm_next_y = fm_shift_y + target_y;
				move_menu();
			}	
			float_menu();
		}
	
}

function move_menu()
{
	
	if(fm_next_y < (nMenuYPos+8))
	{
		fm_next_y=nMenuYPos;		
	}
	
	
    if (document.layers)
    {  
        floating_menu.top = fm_next_y;
    }
    else
    {    
        floating_menu.style.top = fm_next_y + 'px';
    }
}

function compute_shifts()
{  
    fm_shift_y = has_inner
        ? pageYOffset
        : has_element
          ? document.documentElement.scrollTop
          : document.body.scrollTop;
    if (target_y < 0)
        fm_shift_y += has_inner
            ? window.innerHeight
            : has_element
              ? document.documentElement.clientHeight
              : document.body.clientHeight;
}

function float_menu()
{
    var step_y;

    compute_shifts();

    step_y = (fm_shift_y + target_y - fm_next_y) * .07;
    if (Math.abs(step_y) < .5)
        step_y = fm_shift_y + target_y - fm_next_y;
	
	
	//check if gots to the bottom	
	float_y_pos=(fm_next_y + step_y) + document.getElementById(fm_id).offsetHeight;
		
	bottomStop = findPosY(document.getElementById('bottomTable'));
	
	
	
	if(float_y_pos <= bottomStop)			
	{
		if((fm_next_y+ step_y)==nMenuYPos)
			fm_next_y =nMenuYPos;
			
		if (Math.abs(step_y) > 0 && (fm_next_y+ step_y) >= nMenuYPos)
		{			
			fm_next_y += step_y;
			
			move_menu();
		}
	}
	else
	{
		float_div_height=document.getElementById(fm_id).offsetHeight;
		fm_next_y=bottomStop-float_div_height-1;
		move_menu();	
	}
	//window.status=screen.height + "  div height=" + document.getElementById("floatdiv").offsetHeight;
//	window.status="float_y_pos=" + float_y_pos + "  menu pos=" + nMenuYPos+ " fm_next_y= "+fm_next_y+ " step_y= "+step_y+ " bottomStop="+bottomStop;
    setTimeout('float_menu()', 15);
};


