
//	(c) copyright 2003 DAVstudio, Fenna Westerdiep (BNO)
//	Author: Bas van Gaalen

// Define some variables & constants
var menuTimeout = 250;
var pMenu = -1;
var aMenu = -1;
var pDot = -1;
var mousey = -1;
var openmenu = '';

// Show menu dot and start time-out for sub
function showSub(menu) {
	if (menu != pMenu) imgSwitch('imgmenu'+menu, 'imgMDot');
	aMenu = menu;
	pDot = menu;
	setTimeout('activateSub('+menu+')', menuTimeout);
}

// Hide menu dot
function noSub() {
	if (pDot != pMenu) imgSwitch('imgmenu'+pDot, 'imgMSpc');
	aMenu = -1;
}

// Time-out func for sub-menu: show sub-menu
function activateSub(menu) {
	if (aMenu != menu || menu == pMenu) return false;
	if (pMenu != -1) {
		imgSwitch('imgmenu'+pMenu, 'imgMSpc');
		getElmCss('submenu'+pMenu).display = 'none';
	}
	imgSwitch('imgmenu'+menu, 'imgMTri');
	getElmCss('submenu'+menu).display = 'block';
	getElmCss('submenu999').display = 'none';
	pMenu = menu;
	return true;
}

// Show sub-menu dot
function showSubDot(mMain, mSub) {
	imgSwitch('imgsubmenu'+mMain+'_'+mSub, 'imgMDot');
}

// Hide sub-menu dot
function hideSubDot(mMain, mSub) {
	imgSwitch('imgsubmenu'+mMain+'_'+mSub, 'imgMSpc');
}

// Open sub menu
function openSub() {
	setTimeout('showMenu(\'sub\')', 100);
}

// Open main menu
function openMain() {
	setTimeout('showMenu(\'main\')', 100);
}

function showMenu(menu) {
	if (menu == 'sub') {
		getElmCss('mainmenu').visibility = 'hidden';
		getElmCss('submenu').visibility = 'visible';
		openmenu = 'sub';
	} else {
		getElmCss('submenu').visibility = 'hidden';
		getElmCss('mainmenu').visibility = 'visible';
		openmenu = 'main';
	}
}

// Mouse-move handler, records vertical mouse position
document.onmousemove = function(evt) {
	evt = evt?evt:event;
	mousey = evt.pageY?evt.pageY:evt.y;
	if (mousey > 240 && openmenu == 'main') openSub();
}

// Display and potion mail/print/top floater
function updateFloater() {

	// Only mess around with floater, if it's in the document
	if (getElm('floater')) {

		// Fixed for Mozilla/Netscape
		getElmCss('floater').position = ie?'absolute':'fixed';

		// Get some page properties
		var floaterHeight = 40+getElm('floater').offsetHeight; // 40 for spacing
		var sidebarHeight = getElm('sidebar').offsetHeight;
		var sidebarContentHeight = getElm('sidebar').firstChild?getElm('sidebar').firstChild.offsetHeight:0;

		if ((sidebarContentHeight+floaterHeight) > sidebarHeight) {

			// Not enough space in sidebar, fix floater in gray area
			getElmCss('floater').top = (110+sidebarHeight)+'px';

		} else {

			var diff, floaterPos;

			// Space in sidebar, calculate floater position
			if (!ie) { // Non-IE specific code

				// First position estimate
				floaterPos = Math.min(30+sidebarHeight, getWinHeight()-100);

				// Correct position for bottom of sidebar
				if ((sidebarHeight+100) > getWinHeight()) {
					diff = (getWinHeight()+getWinPos())-sidebarHeight-floaterHeight;
					if (diff > 0) floaterPos -= diff;
				}
				
				// Correct position for top of sidebar
				if ((getWinPos()+floaterPos) < (150+sidebarContentHeight)) floaterPos = 150+sidebarContentHeight-getWinPos();

			} else { // IE specific code

				// First position estimate
				floaterPos = getWinPos()+getWinHeight()-100;

				// Correct position for bottom of sidebar
				diff = floaterPos-sidebarHeight;
				if (diff > 0) floaterPos -= diff;

				// Correct position for top of sidebar
				if (floaterPos < (150+sidebarContentHeight)) floaterPos = 150+sidebarContentHeight;

			}
         
			// Set floater position
			getElmCss('floater').top = floaterPos+'px';

		}

		getElmCss('floater').visibility = 'visible';
	}
	
}

// Handlers
window.onload = updateFloater;
window.onresize = updateFloater;
window.onscroll = updateFloater;
