
// Floating Bar (v1.0) by Orr Siloni. November 2003.

// if there are multiple scripts in the page, put the onload in the body tag: <body onload="fsb_init();">
window.onload = fInit;

// the id of the div of the floating menu
var vFloatingBar = "Menu1";

// width of the main table
var vMainWidth = 778;

// how much from the left from the start of the main table
var vLeftMargin = 524;

// how much from the right end of the window. applies only for pages with <html dir=rtl> when the window size is smaller than vMainWidth
var vRightMargin = 8;

// how much from the right
var vTopMargin = 140;

// true if top of menu should remain fixed until margin reduces to the value of vTopPadding
var vFixedTop = true;

// minimal padding maintained from the top of the page. applies only if vFixedTop is set to true
var vTopPadding = 0;

// minimal padding maintained from the bottom of the page. applies only if the menu exceeds the bottom of the visible screen
var vBottomPadding = 202;

// === DO NOT CHANGE SCRIPT BELOW THIS LINE ===

var oFloatingBar = null;
var vScrollHeight;
var vPrevScroll = 0;

function fInit(){
	oFloatingBar = document.all(vFloatingBar);
	if (oFloatingBar == null) return;
	oFloatingBar.style.position = "absolute";
	vScrollHeight = document.body.scrollHeight;
	fPlaceBar();
	oFloatingBar.style.display = "inline";
	window.onresize = fPlaceBar;
	window.onscroll = fPlaceBar;
}

function fPlaceBar(){
	var vBodyWidth = document.body.clientWidth;
	var vBodyHeight = document.body.offsetHeight;
	
	//if (document.dir == "rtl") vBodyWidth -= 20;	// compensate for scrollbar
	
	// set left position
	if (vBodyWidth < vMainWidth){
		if (document.dir == "rtl"){
			oFloatingBar.style.pixelLeft = vBodyWidth - oFloatingBar.clientWidth - vRightMargin;
		} else {
			oFloatingBar.style.pixelLeft = vLeftMargin;
		}
	} else {
		oFloatingBar.style.pixelLeft = (vBodyWidth - vMainWidth)/2 + vLeftMargin;
	}
	
	// set top position
	if (vPrevScroll < document.body.scrollTop){	// check for bottom padding only if scrolling down
		if (oFloatingBar.style.pixelTop + oFloatingBar.offsetHeight >= vScrollHeight - vBottomPadding){
			oFloatingBar.style.pixelTop = vScrollHeight - oFloatingBar.offsetHeight - vBottomPadding;
			return;
		}
	}
	vPrevScroll = document.body.scrollTop;
	if (vFixedTop){		
		if (document.body.scrollTop > vTopMargin - vTopPadding){
			oFloatingBar.style.pixelTop = vTopPadding + document.body.scrollTop;
		} else {
			oFloatingBar.style.pixelTop = vTopMargin;
		}
	} else {
		oFloatingBar.style.pixelTop = vTopMargin + document.body.scrollTop;
	}
}