// Menus initialisieren
var cPop;
var pop_snap = document.getElementById('pop_snap');

var pop1 = document.getElementById('pop1');
var pop2 = document.getElementById('pop2');
var pop3 = document.getElementById('pop3');

if (pop1) {
  pop1.show   = show ;
  pop1.hide   = hide ;
  pop1.snapTo = snapTo;
  pop1.maint  = 0;
  pop1.onmouseover = function() { this.show(); }
  pop1.onmouseout  = function() { this.hide(); }
}

if (pop2) {
  pop2.show   = show ;
  pop2.hide   = hide ;
  pop2.snapTo = snapTo;
  pop2.maint  = 0;
  pop2.onmouseover = function() { this.show(); }
  pop2.onmouseout  = function() { this.hide(); }
}

if (pop3) {
  pop3.show   = show ;
  pop3.hide   = hide ;
  pop3.snapTo = snapTo;
  pop3.maint  = 0;
  pop3.onmouseover = function() { this.show(); }
  pop3.onmouseout  = function() { this.hide(); }
}

function show() {
// bisheriges Menu verbergen
  if (cPop && cPop!=this) cPop.hide();
  if ((capObj = arguments[0]) && !this.maint) {
// neue Positionierung
    if (pop_snap) {
// am Snap-Objekt (div id=pop_snap)
      this.snapTo(capObj,pop_snap,5,0);
      this.snap_x = capObj;
      this.snap_y = pop_snap;
    }
    else {
// am Menupunkt
      this.snapTo(capObj,capObj,5,capObj.offsetHeight);
      this.snap_x = capObj;
      this.snap_y = capObj;
    }
    this.ofs_x = 5;
    this.ofs_y = 0;
  }
  ////this.rollOpen();
// Menu einblenden und merken
  this.style.visibility = 'visible';
  cPop = this;

  if (msie) this.style.filter = 'Alpha(opacity=100, finishopacity=60, style=1)';
}

// Subfunktionen
function hide() {
  this.style.visibility = 'hidden';
}

function resetNav() {
  if (cPop && cPop.hide) cPop.hide();
  refreshNav();
}

function refreshNav() {
  pop1.hide();
  pop2.hide();
  pop3.hide();
  pop1.maint = 0;
  pop2.maint = 0;
  pop3.maint = 0;
}

function snapTo(objx,objy,offsetx,offsety) {
  x = 0; y = 1;  var ofs = [];
  pos = getPos(objx);
  ofs[x] = pos[x];
  if (objx == objy) {
    ofs[y] = pos[y];
  }
  else {
    pos = getPos(objy);
    ofs[y] = pos[y];
  }
  if (this.style && this.style.left) {
    this.style.left = ofs[x] + offsetx;
  }
  if (this.style && this.style.top) {
    this.style.top = ofs[y] + offsety;
  }
// Menu als bereits positioniert markieren
  this.maint = 1;
}

function getPos(obj) {
  var x = (obj.offsetLeft)? obj.offsetLeft : 1;
  var y = (obj.offsetTop)? obj.offsetTop : 1;
  p = obj.offsetParent;
  while (p) {
    x += p.offsetLeft;
    y += p.offsetTop;
    p = p.offsetParent;
  }
  return Array(x,y);
}

function rollOpen() {
  height = pop1.offsetHeight;
  height = (height)? height : 10;
  for (var i=1;i<=height;i++) {
    window.setTimeout(this.setClip(i)+"",1000);
  }
}

function setClip(i) {
    this.style.clip = 'rect(0,150,'+i+',0)';
}

