var aktywnyPrzycisk = null;
var currentMenuId = 0;

document.onclick = documentClick;

function documentClick(event) {
	if (aktywnyPrzycisk != null){
		UkryjWarstwe( aktywnyPrzycisk);
	}
}

function buttonClick(event, menuId) {
  var przycisk;
  if (document.all){
		przycisk = window.event.srcElement;
  }else{
  	przycisk = event.currentTarget;
  } 
  przycisk.warstwa = document.getElementById(menuId);

  if (aktywnyPrzycisk != null){
    UkryjWarstwe(aktywnyPrzycisk);
 	}	
  if ( przycisk.warstwa != null ){
   PokazButton(przycisk);
   aktywnyPrzycisk = przycisk;
  }
  return false;
}

function PokazButton(przycisk) {
  var x, y;
  x = getLeft(przycisk);
  y = getTop( przycisk ) + przycisk.offsetHeight;

  przycisk.warstwa.style.left = x + "px";
  przycisk.warstwa.style.top  = y + "px";
  przycisk.warstwa.style.visibility = "visible";
}

function UkryjWarstwe(przycisk) {
	if ( przycisk != null) {
		 przycisk.warstwa.style.visibility = "hidden";
	}
}

function menuMouseover(event,menuId ) {
    buttonClick(event, menuId)
}

function getLeft(element) {
  var x;
  x = element.offsetLeft;
  if (element.offsetParent != null){
    x += getLeft(element.offsetParent);
  }
  return x;
}

function getTop(element) {
  var y;
  y = element.offsetTop;
  if (element.offsetParent != null){
    y += getTop(element.offsetParent);
  }
  return y;
}


