/*
 * Skrypt dla menu_dyn
 */

// czesc w oryginale JavaScript
var thresholdY = 15;		// in pixels; threshold for vertical repositioning of a layer
var ordinata_margin = 53;	// to start the layer a bit above the mouse vertical coordinate

DOM = (document.getElementById) ? 1 : 0;
NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
var loaded = 0;	// to avoid stupid errors of Microsoft browsers
Opera5 = (navigator.userAgent.indexOf("Opera 5") > -1 || navigator.userAgent.indexOf("Opera/5") > -1) ? 1 : 0;

//alert ("DOM "+DOM +"\nNS4 "+NS4+"\nIE4 "+IE4+"\nOpera5 "+Opera5);

// czesc w oryginale JavaScript12

// it works with NS4, Mozilla, NS6, Opera 5, IE
currentY = -1;
currentX = -1;
function grabMouse(e) {
	if ((DOM && !IE4) || Opera5) {
		currentY = e.clientY;
		currentX = e.clientX;
	} else if (NS4) {
		currentY = e.pageY;
		currentX = e.pageX;
	} else {
		currentY = event.y;
		currentX = event.x;
	}
	if (DOM && !IE4 && !Opera5) {
		currentY += window.pageYOffset;
		currentX += window.pageXOffset;
	} else if (IE4 && DOM && !Opera5) {
		currentY += document.body.scrollTop;
		currentX += document.body.scrollLeft;
	}
currentX = 80;
}
if ((DOM || NS4) && !IE4) {
	document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE);
}
document.onmousemove = grabMouse;

function popUp(menuName,on) {
	if (loaded) {	// to avoid stupid errors of Microsoft browsers
		if (on) {
//			moveLayers();
			if (DOM) {
				document.getElementById(menuName).style.visibility = "visible";
			} else if (NS4) {
				document.layers[menuName].visibility = "show";
			} else {
				document.all[menuName].style.visibility = "visible";
			}
		} else {
			if (DOM) {
				document.getElementById(menuName).style.visibility = "hidden";
			} else if (NS4) {
				document.layers[menuName].visibility = "hide";
			} else {
				document.all[menuName].style.visibility = "hidden";
			}
		}
	}
}
/*
function popUp(menuName, on) { 
//alert(on+" popUp "+menuName);

  var v,obj;

  if(!(obj=document[menuName])&&document.all)
    obj=document.all[menuName]; 

  if(!obj && document.getElementById)
    obj=document.getElementById(menuName); 

//alert(obj);	
  if ((obj)!=null) { 
//alert("nie nul");	
    if (obj.style) { 
//alert("styl "+on);	
      obj=obj.style; 
      if(on) v='visible';
      else v='hidden';
    }
    obj.visibility=v; 
  }
}
*/
function moveLayerY(menuName, x, ordinata, offsetX) {
	if (loaded) {	// to avoid stupid errors of Microsoft browsers
		if (ordinata != -1 && !isNaN(ordinata)) {	// The browser has detected the mouse position
			if (DOM) {
				document.getElementById(menuName).style.left = x + offsetX;
				appoggio = parseInt(document.getElementById(menuName).style.top);
				if (isNaN(appoggio)) appoggio = 0;
				if (Math.abs(appoggio + ordinata_margin - ordinata) > thresholdY)
					document.getElementById(menuName).style.top = ordinata - ordinata_margin;
			} else if (NS4) {
				document.layers[menuName].left = x + offsetX;
				if (Math.abs(document.layers[menuName].top + ordinata_margin - ordinata) > thresholdY)
					document.layers[menuName].top = ordinata - ordinata_margin;
			} else {
				document.all[menuName].style.pixelLeft = x + offsetX;
				if (Math.abs(document.all[menuName].style.pixelTop + ordinata_margin - ordinata) > thresholdY)
					document.all[menuName].style.pixelTop = ordinata - ordinata_margin;
			}
		}
	}
}

/*
if (NS4) {
	document.onmousedown = function() { shutdown(); }
} 
else {
	document.onclick = function() { shutdown(); } 
}
*/
