// Floating Bar (v1.1 Meholel Revision) by Orr Siloni. December 2004.

// the FloatingBar is activated from GeneralLoader.js
//window.onload = fFloatingBarInit;

// the id of the div of the floating menu
var fb_vFloatingBar = "P10";

// width of the main table
var fb_vMainWidth = 778;

// how much from the left from the start of the main table
var fb_vLeftMargin = 630;

// how much from the top
var fb_vTopMargin = 200;

// how much from the right. applies only if the window is smaller than fb_vMainWidth
var fb_vRightMargin = 0;

// true if top of menu should remain fixed until margin reduces to the value of vTopPadding
var fb_vFixedTop = false;

// minimal padding maintained from the top of the page. applies only if vFixedTop is set to true
var fb_vTopPadding = 200;

// minimal padding maintained from the bottom of the page. applies only if the menu exceeds the bottom of the visible screen
var fb_vBottomPadding = 30;

// === DO NOT CHANGE SCRIPT BELOW THIS LINE ===

var fb_oFloatingBar = null;
var fb_vScrollHeight;
var fb_vPrevScroll = 0;

/* this variable is read by the GeneralEventHandler. 
It has two uses:
1. To indicate to the GeneralEventHandler that the FloatingBar is present and should be initialized
2. To set the 'onscroll' and 'onresize' in this script On and Off. */
var fb_vFloatingBarState = false;

function fb_fFloatingBarInit(){
	fb_oFloatingBar = document.getElementById(fb_vFloatingBar);
	if (fb_oFloatingBar == null) return;
	fb_oFloatingBar.style.position = "absolute";
	fb_vScrollHeight = document.body.scrollHeight;
	fb_fPlaceBar();
	fb_oFloatingBar.style.display = "inline";
	//window.onresize = fb_fPlaceBar;
	//window.onscroll = fb_fPlaceBar;
	fb_vFloatingBarState = true;
}

function fb_fPlaceBar(){
	var fb_vBodyWidth = document.body.clientWidth;
	var fb_vBodyHeight = document.body.offsetHeight;
	
	//if (document.dir == "rtl") fb_vBodyWidth -= 20;	// compensate for scrollbar
	
	// set left position
	if (fb_vBodyWidth < fb_vMainWidth){
		if (document.dir == "rtl"){
			fb_oFloatingBar.style.pixelLeft = fb_vBodyWidth - fb_vRightMargin - fb_oFloatingBar.offsetWidth;
		} else {
			fb_oFloatingBar.style.pixelLeft = fb_vLeftMargin;
		}
	} else {
		fb_oFloatingBar.style.pixelLeft = (fb_vBodyWidth - fb_vMainWidth)/2 + fb_vLeftMargin;
	}
	
	// set top position
	if (fb_vPrevScroll < document.body.scrollTop){	// check for bottom padding only if scrolling down
		if (fb_oFloatingBar.style.pixelTop + fb_oFloatingBar.offsetHeight >= fb_vScrollHeight - fb_vBottomPadding){
			fb_oFloatingBar.style.pixelTop = fb_vScrollHeight - fb_oFloatingBar.offsetHeight - fb_vBottomPadding;
			return;
		}
	}
	fb_vPrevScroll = document.body.scrollTop;
	if (fb_vFixedTop){		
		if (document.body.scrollTop > fb_vTopMargin - fb_vTopPadding){
			fb_oFloatingBar.style.pixelTop = fb_vTopPadding + document.body.scrollTop;
		} else {
			fb_oFloatingBar.style.pixelTop = fb_vTopMargin;
		}
	} else {
		fb_oFloatingBar.style.pixelTop = fb_vTopMargin + document.body.scrollTop;
	}
}
