  ///////////////////////////////////////////////
  // Zmienne uzytkowe

  var isIE = (document.all) ? true : false; 
  var isNS4 = (document.layers) ? true : false; 
  var isNS6 = (document.getElementById&&!document.all) ? true : false;

  var ns4 = isNS4;
  var ie4 = isIE;

  // Zmienna przechowujaca identyfikatory uruchomionych przerwan
  var timerStore = Array;
  // Zmienna przechowujaca obiekty, ktore maja byc wywolane w poszczegolnych przerwaniach
  var timerObjStore = Array();
  // Zmienna przechowujaca nazwy metod, ktore maja byc uruchomione dla poszczegolnych obiektow
  var timerMethodStore = Array();
  // Zmienna przechowujaca argumenty, z ktorymi maja byc wywolane metody
  var timerArgsStore = Array();
  // Zmienna przechowujaca identyfikator aktualnie wolnego przerwania
  var timerEventId = 0;

  // pokazywanie / chowanie warstw

  function show(id) {
    if (isNS6) {
      document.getElementById(id).style.visibility='visible';
    } //if
    else if (isNS4) {
      document.layers[id].visibility = "show";
    } //else if
    else if (isIE) {
      document.all[id].style.visibility = "visible";
    } //else if
  }

  function hide(id) {
    if (isNS6)
      document.getElementById(id).style.visibility='hidden';
    else if (isNS4)
      document.layers[id].visibility = "hide";
    else if (isIE) 
      document.all[id].style.visibility = "hidden";

  }


  // Wyszukiwanie warstw

  function getLayer(layer_name) {
    if (isNS6)
      return document.getElementById(layer_name);
    else if (ns4)
      return document.layers[layer_name];
    else if (ie4) 
      return document.all[layer_name];

    return null;
  }
  
  function getLeft(id) {
    if (isNS6)
      return parseInt(document.getElementById(id).style.left);
    else if (ns4)
      return document.layers[id].left;
    else if (ie4) 
      return Number(document.all[id].style.left.substring(0, document.all[id].style.left.indexOf("p")));

    return 0;
  }

  function getTop(id) {
    if (isNS6)
      return parseInt(document.getElementById(id).style.top);
    else if (ns4)
      return document.layers[id].top;
    else if (ie4)
      return Number(document.all[id].style.top.substring(0, document.all[id].style.top.indexOf("p")));

    return 0;
  }

  function getWidth(id) {
    if (isNS6)
      return parseInt(document.getElementById(id).style.width);
    else if (ns4)
      return 180 /*lay.width*/;
    else if (ie4)
      return Number(document.all[id].style.width.substring(0, document.all[id].style.width.indexOf("p")));

    return 0;
  }

  function getHeight(id) {
    if (isNS6)
      return parseInt(document.getElementById(id).style.height);
    else if (ns4)
      return 110 /*lay.height*/;
    else if (ie4)
      return Number(document.all[id].style.height.substring(0, document.all[id].style.height.indexOf("p")));

    return 0;
  }

  /* Obsluga kursora myszy */

  function getMenuPositionX (a_name, extra) {
    var x=100;
    if (ns4) {
      for (var i=0; i<document.anchors.length; i++) {
        if (document.anchors[i].name==a_name) { 
          x=document.anchors[i].x;
          break; 
        }
      }
      x+=5;
      if (extra) {
          x+=0;
      }
    } else if (ie4) {
      var el=document.all[a_name];
      var ol=el.offsetLeft;
      while ((el=el.offsetParent) != null) { 
        ol += el.offsetLeft; 
      }
      x=ol+23;
      if (extra) {
          x+=0;
      }
    }
    else if (isNS6) {
      var el=document.getElementById(a_name);
      var ol=el.offsetLeft;
      while ((el=el.offsetParent) != null) { 
        ol += el.offsetLeft; 
      }
      x=ol+5;
      if (extra) {
          x+=0;
      }
    }
    return x;
  } /*getMenuPositionX*/

  function getMenuPositionY (a_name, extra) {
    var y=50;
    if (ns4) {
      for (var i=0; i<document.anchors.length; i++) {
        if (document.anchors[i].name==a_name) { 
          y=document.anchors[i].y;
          break; 
        }
      }
      y-=23;
      if (extra) {
          y+=3;
      }
    } else if (ie4) {
      var el=document.all[a_name];
      var ot=el.offsetTop;
      while((el=el.offsetParent) != null) { 
        ot += el.offsetTop; 
      }
      y=ot-5;
      if (extra) {
          y-=5;
      }
    }
    else if (isNS6) {
      var el=document.getElementById(a_name);
      var ot=el.offsetTop;
      while((el=el.offsetParent) != null) { 
        ot += el.offsetTop; 
      }
      y=ot-23;
      if (extra) {
          y+=3;
      }
    }
    return y;
  } /*getMenuPositionY*/

  /* obsluga menu */

  // Tabica wyswietlonych warstw
  var showed = new Array();
  showed[0] = 0;
  // Tablica pokazujaca warswe, otworzona przez warstwe maciezysta
  // uzywana do szybkiego chowania warstw w sytuacji, gdy trzeba otworzyc nowa
  // - przejscie od jednej opcji menu do drugiej
  var opened_by = new Array();
  var opened_level = new Array();
  // Tablica przechowuje informacje, ktora z warstw sa przyblokowene przed schowaniem
  // z powodu tego, ze otworzyly nowe submenu - zapisy kogo - kto blokuje
  var blocked_by = new Array();
  // Taka sama jak wyzej, tylko odwrotne zapisy (kto - kogo blokuje)
  var blocking = new Array();
  // Tablica przechowuje identyfikatory tych warst, ktore mozna juz schowac, 
  // jednak chowanie jest przyblokowane z powodu utworzenia submenu
  var ready_to_hide = new Array();
  // Identyfikator ostatnio otwartej pozycji w menu
//  current_menu = null;
  var timerID = new Array();
 
  function htS(pageid, parent_id, issub) {
    if (issub && (! showed[pageid])) {
		hMA();
	}
  }


  function tS(pageid, parent_id, issub) {
    if (issub && (! showed[pageid])) {
      showed[pageid] = 1;
      cH(pageid);
      ready_to_hide[pageid] = 0;
      if (blocked_by[parent_id]) {
        blocking[blocked_by[parent_id]] = 0;
      }
      blocked_by[parent_id] = pageid;
      if (opened_by[parent_id]) {
        hideMenuNow(opened_by[parent_id]);
      }
      opened_by[parent_id] = pageid;
      blocking[pageid] = parent_id;
      moveDiv(getMenuPositionX('a'+pageid, (! showed[parent_id])), getMenuPositionY('a'+pageid, (! showed[parent_id])), 'submenu_' + pageid);
      show('submenu_' + pageid);
    }
    return true;
  }

  function uS(pageid, issub) {
    if (issub) {
      pH(pageid);
    }
    return true;
  }

  function hM(parent_id) {
    if (opened_by[parent_id]) {
    hideMenuNow(opened_by[parent_id]);
   	}
 }

  function hMA() {
	for (elem in showed)
	{
		if (elem != 0)
		{
			//alert (elem);
		    hideMenuNow(elem);
		}

	}
 }

  function pH(page_id) {

    // Przygotowuje menu do ukrycia - ustawia timer na 1 sekunde
    timerID[page_id] = setTimeout("hideMenu('" + page_id + "')", 2000);
  }

  function cH(page_id) {
    // Anuluje chowanie warstwy, ktora zostala ustawiona w kolejce do ukrycia
    if (timerID[page_id]){
      clearTimeout(timerID[page_id]);
      timerID[page_id] = 0;
      ready_to_hide[page_id] = 0;
    }
  }

  function hideMenu(page_id) {
    // Przygotowuje do ukrycia warstwy
    if (! blocked_by[page_id]) {
      showed[page_id] = 0;
      cH(page_id);
      hide('submenu_' + page_id);
      if (blocking[page_id]) {
        // jezeli aktualnie chowana warstwa blokowala ukrycie innej warstwy
        blocked_id = blocking[page_id];
        // to odblokowujemy te inna - parentMenu
//        opened_by[page_id] = 0;
        blocking[page_id] = 0;
        if (blocked_by[blocked_id] == page_id) {
          blocked_by[blocked_id] = 0;
          if (ready_to_hide[blocked_id]) {
            // jezeli blokowana warstwa byla gotowa do schowania, to ja chowamy
            hideMenu(blocked_id);
          }
        }
      }
    } else {
      ready_to_hide[page_id] = 1;
    }
  }

  function hideMenuNow(page_id) {
    // Chowa warstwe natychmiast, ukrywajac jednoczesnie wszystkie warstwy 
    // otworzone powyzej 
    cH(page_id);
    hide('submenu_' + page_id);
    blocked_id = blocking[page_id];
    blocking[page_id] = 0;
    blocked_by[blocked_id] = 0;
    showed[page_id] = 0;
    if (opened_by[page_id]) {
      opened_id = opened_by[page_id];
      opened_by[page_id] = 0;
      hideMenuNow(opened_id);
    }
  }


  function moveDiv(x,y,div_name) {
    if(isNS4){ 
      eval("document." + div_name  + ".top=" + y);
      eval("document." + div_name + ".left=" + x);
    } else
      if(isNS6) {
        document.getElementById(div_name).style.top = y + "px";
        document.getElementById(div_name).style.left = x + "px";
      } else
        if(isIE) {
          eval(div_name + ".style.top=" + y);
          eval(div_name + ".style.left=" + x);
        }
  }

  function getLayerX (div_name) {
        var layer = getLayer (div_name);
        var x=100;
        if (ns4) {
          x=layer.pageX;
        }
        else if (ie4) {
            var el=layer;
            var ol=el.offsetLeft;
            while ((el=el.offsetParent) != null) { 
                ol += el.offsetLeft; 
            }
            x=ol;
        }
        else if (isNS6) {
            var el=layer;
            var ol=el.offsetLeft;
            while ((el=el.offsetParent) != null) { 
                ol += el.offsetLeft; 
            }
            x=ol;
        }
        return x;
    } /*getLayerX*/

    function getLayerY (div_name) {
        var layer = getLayer (div_name);
        var y=50;
        if (ns4) {
            y=layer.pageY;
        }
        else if (ie4) {
            var el=layer;
            var ot=el.offsetTop;
            while((el=el.offsetParent) != null) { 
                ot += el.offsetTop; 
            }
            y=ot;
        }
        else if (isNS6) {
            var el=layer;
            var ot=el.offsetTop;
            while((el=el.offsetParent) != null) { 
                ot += el.offsetTop; 
            }
            y=ot;
        }
        return y;
    } /*getLayerY*/

  function sm (id, parent_id, level) {
     var styl = glss (id);
    if (styl) {
      if (styl.display == 'block') {
        xm (parent_id, level);
        styl.display = 'none';
        opened_by[parent_id] = 0;
        opened_level[parent_id] = 0;
		changeImages('g_'+id , 'gallery/system/itd_'+level+'.gif');
		} //if
      else {
        xm (parent_id, level);
        styl.display = 'block';
        opened_by[parent_id] = id;
        opened_level[parent_id] = level;
		changeImages('g_'+id , 'gallery/system/itu_'+level+'.gif');
      } //else
    } //if

    return false;
  } /*sm*/

  function xm (parent_id, level) {
    if (opened_by[parent_id] > 0) {
      xm (opened_by[parent_id], opened_level[parent_id]);
      var styl = glss (opened_by[parent_id]);
      if (styl) {
        styl.display = 'none';
		changeImages('g_'+opened_by[parent_id] , 'gallery/system/itd_'+opened_level[parent_id]+'.gif');
        opened_by[parent_id] = 0;
		opened_level[parent_id] =0;
      } //if
    } //if
  } /*xm*/

  function glss (id) {
    if (id != "") {
      var styl;
      if (isIE) {
        styl = document.all['submenu_'+id].style;
	//	alert( document.all['submenu_' + id].style);

      } //if
      else if (isNS6) {
        styl = document.getElementById('submenu_'+id).style;
	//	alert(document.getElementById('submenu_'+id).style.display);
      } //else if
      else if (isNS4) {
        return false;
      } //else if
      return styl;
    } //if
    else {
      return false;
    } //else
  } /*gls*/

 function changeImages() {
  var tmp;
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

