// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0;
var tempY = 0;


// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
} else { // grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
} 
// catch possible negative values in NS4
if (tempX < 0){tempX = 0}
if (tempY < 0){tempY = 0} 
// show the position values in the form named Show
// in the text fields named MouseX and MouseY
 // document.Show.MouseX.value = tempX
 // document.Show.MouseY.value = tempY
return true;
}

function AdjustMenuPosition (theMenu, offsetX, offsetY, menuPosStepX, menuPosStepY) {
 
 var menuId = 'menuDiv' + theMenu;
 var styleObject = getStyleObject(menuId);
 
 if (! menuPosStepX) {
  // document.all['menuDiv' + theMenu].style.left = (tempX + offsetX).toString() + 'px';
  styleObject.left = (tempX + offsetX).toString() + 'px';
 } else { // правим стъпка по X
  // document.all['menuDiv' + theMenu].style.left = (Math.round(tempX / menuPosStepX) * menuPosStepX  + offsetX).toString() + 'px';
  styleObject.left = (Math.round(tempX / menuPosStepX) * menuPosStepX  + offsetX).toString() + 'px';
 } // правим стъпка по X
 
 if (! menuPosStepY)
  // document.all['menuDiv' + theMenu].style.top = (tempY + offsetY).toString() + 'px';
  styleObject.top = (tempY + offsetY).toString() + 'px';
 else { // правим стъпка по Y
  if (Math.round(tempY / menuPosStepY) * menuPosStepY  + offsetY > 0)
   // document.all['menuDiv' + theMenu].style.top = (Math.round(tempY / menuPosStepY) * menuPosStepY  + offsetY).toString() + 'px';
   styleObject.top = (Math.round(tempY / menuPosStepY) * menuPosStepY  + offsetY).toString() + 'px';
  else 
   // document.all['menuDiv' + theMenu].style.top =  (menuPosStepY  + offsetY).toString() + 'px';
   styleObject.top =  (menuPosStepY  + offsetY).toString() + 'px';
 } // правим стъпка по Y
} // function AdjustMenuPosition


function ShowMenuPos (theMenu, offsetX, offsetY, doNotHide, menuPosStepX, menuPosStepY) {

 AdjustMenuPosition (theMenu, offsetX, offsetY, menuPosStepX, menuPosStepY);
 ShowMenu(theMenu);
 
 for (counter = 0; counter < ids.length; counter++) {
   if (doNotHide.toString().indexOf(ids[counter])!==-1) {
    // skip++;
   } else 
	changeObjectVisibility('menuDiv' + ids[counter], 'hidden');
	// var menuTitle = getStyleObject('menuTitle' + counter);
	// menuTitle.backgroundColor = '#000000';
 } // for
 
} // function ShowMenuPos

 




// Copyright © 2000 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.
//
// ************************
// layer utility routines *
// ************************

function getStyleObject(objectId) {
    // cross-browser function to get an object s style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this will not find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we could not find the object, so we can not change its visibility
	return false;
    }
} // changeObjectVisibility


function ShowMenu(who)
{

    var menuId = 'menuDiv' + who;
    if(changeObjectVisibility(menuId, 'visible')) {
	return true;
    } else {
	return false;
    }
}

function HideMenu(who)
{
 var id="menuDiv"+who;
 if (who) {
  changeObjectVisibility(id, 'hidden');
  // document.forms['test'].debug.value = 'HideMenu ' + id;
 }  
} // function HideMenu

function ShowAnyDiv(who)
{

    var menuId = who;
    if(changeObjectVisibility(menuId, 'visible')) {
	return true;
    } else {
	return false;
    }
}

function HideAnyDiv(who)
{
 var id = who;
 if (who) {
  changeObjectVisibility(id, 'hidden');
  // document.forms['test'].debug.value = 'HideMenu ' + id;
 }  
} // function HideMenu


var ids = new Array ();
var idSunsorted = new Array ();
var startOffset = new Array ();

var alreadyOver = 0;
var tmsubmenus;

function hideAllMenus() {
    for(counter = 0; counter < ids.length; counter++) {
	changeObjectVisibility('menuDiv' + ids[counter], 'hidden');
	var menuTitle = getStyleObject('menuTitle' + counter);
	menuTitle.backgroundColor = '#000000';
    }
}

function showSelMenus (which) {
    which.sort ();

    var iwh = 0;


    for(counter = 0; counter < ids.length; counter++) {
      if (ids[counter] == which[iwh]) {
       ShowMenu(ids[counter]);
       iwh++;
      } else 
       HideMenu(ids[counter]); 
    } // for
}

var constShow = new Array (); // constantly visible menus

