
// Copyright (c)2003 by Fabian Mikołajczak)
// mailto: cyrylus@sedez.iq.pl

odstep_x = -15; //odstep w poziomie pomiedzy poziomami menu
odstep_y = 4; //odstep w pionie pomiedzy poziomami menu
poz = Array(); //poz['menu1']= (0 || 1)
pozr = Array(); // poz['0']='menu1'
omoa = Array();

function shift() {
  if (this.length > 0) { 
    var re=this[0];
    for (var i=0;i<(this.length-1);i++) {
      this[i]=this[i+1];
    }
    this.length--;
    return re;
  }
}

if (!omoa.shift) {
  omoa.shift = shift;
}


function get_poz(string) {
  var f = poz[string];
  if (f==0 || f==1) { 
    return f;
  } else {
    return -1;
  }
}

function put_poz(string,wartosc) {
  var f = poz[string];
  if (f==0 || f==1) { 
    poz[string]=wartosc;
  } else {
    poz[string]=wartosc;
    pozr[pozr.length]=string;
  }  
}

function omv(object) {
  put_poz(object.id,1);
  if (object.id.indexOf("_roz",object.id.length - 5) ==-1) {
    obj = get_object_by_id(object.id + "_roz");
    var x=get_x(object);
    var y=get_y(object);
    if (obj) {
      obj.style.visibility='visible';
      obj.style.left=x+object.offsetWidth+odstep_x;
      obj.style.top=y+odstep_y;
    }
  }
}

function omo(object) {
  omoa[omoa.length]=object.id;
  put_poz(object.id,0);
  setTimeout('hide()',50);
}

function get_object_by_id(string) {
  return document.getElementById(string);
}

function get_x(object) {
  var x=0;
  x=object.offsetLeft
  if (object) {
    while(object.offsetParent.id != "body") {
      x=x+object.offsetParent.offsetLeft;
      object=object.offsetParent;
    }
  }
  return x;
}

function get_y(object) {
  var y=0;
  y=object.offsetTop
  while(object.offsetParent.id != "body") {
    y=y+object.offsetParent.offsetTop;
    object=object.offsetParent;
  }
  return y;
}

function hide(){
  var object=get_object_by_id(omoa.shift());
  if (poz[object.id]==0) {
    var roz = object.id.indexOf("_roz",object.id.length - 5);
    if ( roz==-1) {
      var obj=get_object_by_id(object.id + "_roz");
      if (obj) {
        if (get_poz(obj.id)==0 || get_poz(obj.id)==-1){
          obj.style.visibility='hidden';
        }
      }
    } else {
      obj=get_object_by_id(object.id.substring(0,roz));
      if (obj) { 
        if (poz[obj.id]==0){
          object.style.visibility='hidden';
        }
      }
    }
  }
}


function ksiazka_f() {
    obj = get_object_by_id("ksiazka");
    if (obj) {
      bo = get_object_by_id("body");
      var x=get_x(obj);
      var y=get_y(obj);
      obj.style.visibility='visible';
      obj.style.top=y-10;
      obj.style.left=(bo.offsetWidth/2-117.5);
    }
}
