/*
*  version 1.3 20010205
*  Start date: Jan 30th 2002
*  
*/

isDOM = 1;
isDOM = (document.getElementById) ? true : false;
isNN4 = (document.layers) ? true : false;
isIE = (document.all) ? true : false;
isIE4 = isIE && !isDOM;

var aMenuItems = new Array();
var isMenuToHide = new Array();
var isMenuOpen = new Array();
var isMenuPrepared = new Array();
var isModifying = true;
var tmOut = null;
var oPar;


function initVariables() {

  isMenuToHide = [true, true, true, true, true, true, true, true];
  isMenuOpen = [false, false, false, false, false, false, false, false];
  isMenuPrepared = [false, false, false, false, false, false, false, false];

  aMenuItems = [
  [
  ['Nowosci','Nowosci','nowosci.htm', 1, 'menu00', 'Nowosci w ofercie'],
  ['Publikacje','Publikacje','publikacje.htm', 1, 'menu01'],
  ['Seminaria','Seminaria','seminaria.htm', 1, 'menu02']
  
  ],

  [
  ['CE','CE','ce.htm', 1, 'menu10', 'Sklepy'],
  ['Forum','Forum','http://www.televes.pl/forum/', 1, 'menu16'],
  ['Serwis','Serwis','serwis.htm', 1, 'menu15'],
  ['Download','Download','download.htm', 1, 'menu11'],
  ['Instrukcje Obslugi','Instrukcje Obslugi','instrukcje.htm', 1, 'menu12'],
  ['Karty katalogowe','Karty Katalogowe','karty.htm', 1, 'menu13'],
  ['Katalog produktow','Katalog Produktow','http://satlan.pl/pliki/pdfy/katalog_2006_english.pdf', 1, 'menu14']
 
  ],

  [
  ['Anteny','Anteny','anteny.htm', 1, 'menu22', 'nazwa 3'],
  ['Maszty','Maszty','maszty.htm', 1, 'menu27'],
  ['Asortyment domowy','Asortyment domowy','dom.htm', 1, 'menu20', 'nazwa 3'],
  ['Urzadzenia pomiarowe','Urzadzenia pomiarowe','urzadzenia_pom.htm', 1, 'menu21'],
  ['Stacje czolowe','Stacje czolowe','stacje.htm', 1, 'menu23'],
  ['Wzmacniacze','Wzmacniacze','wzmacniacze.htm', 1, 'menu24'],
  ['Zlacza i gniazda','Zlacza i gniazda','zlacza.htm', 1, 'menu26'],
  ['Akcesoria','Akcesoria','akcesoria.htm', 1, 'menu25']
	
  ]

  ] ;

  oPar = {
        nStartLeftPos     : -100,
        nStartTopPos      : -100,
        nAlwaysTop        : 94,
        nLeftRightPadding : 4,
        nTopBottomPadding : 2,
        nHeight           : 18,
        nRightSpace       : 4,
        nBorderWidth      : 1,
        nzIndexMin        : 5000,
        nMiliseconds      : 150,
        nScreenWidth      : 0,
        strBack1          : '_1',
        strBack2          : '_2',
        strLink           : '_0',
        strStartID        : 'menuID',
        strBackName       : 'back',
        strMidName        : 'middle',
        strFont           : 'Verdana,Arial,Helvetica,sans-serif'
  } ;
  init1();
  return true;
}

if(!isDOM) {
  window.onResize = init1;
  window.onFocus = init1;
  window.onBlur = function() { if(tmOut) clearInterval(tmOut); };
}
// else initIE();


function initIE() {
  if(isIE && isDOM) setTimeout('initVariables()', 2000);
  return true;
}


function init() {
  if(!isDOM)
    setTimeout('initVariables()', 500);
  else 
// if(!isIE)
    initVariables();
  return false;
}


function uninit() {
  delete aMenuItems;
  if(tmOut) clearInterval(tmOut);
  return true;
}


function init1() {
  if(tmOut) clearInterval(tmOut);
  bTest = false;
  if(!isDOM) {
    if(document.menuID2)
      bTest = true;
  }
  else 
    if(isIE) {
      if(document.getElementById('menuID2'))
        bTest = true;
    }
    else bTest = true;

  if(bTest) {
    for(var nI = 0; nI < aMenuItems.length; nI++)
      prepareMenu(aMenuItems[nI], nI);
    if(!isDOM)
      moveMenus();
    if(tmOut) clearInterval(tmOut);
    tmOut = setInterval('runMenus()', oPar.nMiliseconds); 
    isModifying = false;
  }
  else setTimeout('init1()', 500);
}


function moveMenus() {

  if(!isMenuPrepared[aMenuItems.length - 1]) return false;

  if(isNN4) {
    var nTopDiff = getTop(eval('document.' + oPar.strStartID + '0')) + 15 - aMenuItems[0][0][8].top;
    var nLeftDiff;
    for(var nIndex = 0; nIndex < aMenuItems.length; nIndex++) {

      nLeftDiff = getLeft(eval('document.' + oPar.strStartID + nIndex)) - aMenuItems[nIndex][0][8].left;

      aMenuItems[nIndex][0][10].left += nLeftDiff;
      aMenuItems[nIndex][0][11].left += nLeftDiff;
      aMenuItems[nIndex][0][10].top += nTopDiff;
      aMenuItems[nIndex][0][11].top += nTopDiff;

      for(var nSubIndex = 0; nSubIndex < aMenuItems[nIndex].length; nSubIndex++) {
        aMenuItems[nIndex][nSubIndex][8].left += nLeftDiff;
        aMenuItems[nIndex][nSubIndex][8].top += nTopDiff;
        aMenuItems[nIndex][nSubIndex][9].left += nLeftDiff;
        aMenuItems[nIndex][nSubIndex][9].top += nTopDiff;
      }
    }
  } // end of NN4
  else if(isDOM) {
    var nTopDiff = getTop(document.getElementById(oPar.strStartID + '0')) + 15 - aMenuItems[0][0][7];
    var nLeftDiff;
    for(var nIndex = 0; nIndex < aMenuItems.length; nIndex++) {

      nLeftDiff = getLeft(document.getElementById(oPar.strStartID + nIndex)) - aMenuItems[nIndex][0][6];

      document.getElementById(aMenuItems[nIndex][0][4] + oPar.strBack1).style.left = (nLeftDiff + aMenuItems[nIndex][0][6] - (2 * oPar.nBorderWidth)) + 'px';
      document.getElementById(aMenuItems[nIndex][0][4] + oPar.strBack2).style.left = (nLeftDiff + aMenuItems[nIndex][0][6] - (1 * oPar.nBorderWidth)) + 'px';
      document.getElementById(aMenuItems[nIndex][0][4] + oPar.strBack1).style.top = (nTopDiff + aMenuItems[nIndex][0][7] - (2 * oPar.nBorderWidth)) + 'px';
      document.getElementById(aMenuItems[nIndex][0][4] + oPar.strBack2).style.top = (nTopDiff + aMenuItems[nIndex][0][7] - (1 * oPar.nBorderWidth)) + 'px';

      for(var nSubIndex = 0; nSubIndex < aMenuItems[nIndex].length; nSubIndex++) {
        document.getElementById(aMenuItems[nIndex][nSubIndex][4]).style.left = (nLeftDiff + aMenuItems[nIndex][0][6]) + 'px';
        document.getElementById(aMenuItems[nIndex][nSubIndex][4]).style.top = (nTopDiff + aMenuItems[nIndex][nSubIndex][7]) + 'px';
      }
    }
  }
  return true;
}


function prepareMenu(aMI, nI) {

  if(isMenuPrepared[nI]) return false;
  if(isNN4) {
    var nMaxWidth = 0;
    var nSeparatorCount = 0;
    var strNothing = '&nbsp;';

    test = new Layer(500, window);
    for(nIndex = 0; nIndex < aMI.length; nIndex++) {
      strTest = '<table border="0"><tr><td><font face="Verdana,Arial,Helvetica,sans-serif" point-size="7.5"><b>' + aMI[nIndex][0] + '</b></font></td></tr></table>';
      test.document.write(strTest);
      test.document.close();
      nMaxWidth = Math.max(nMaxWidth, test.document.width);
      if(aMI[nIndex][3]) nSeparatorCount++;
    }
    delete test;

    aMI[0][10] = new Layer(500, window);
    aMI[0][10].left = (oPar.nStartLeftPos - (2 * oPar.nBorderWidth) + 100 * nI);
    aMI[0][10].top = (oPar.nStartTopPos - (2 * oPar.nBorderWidth));
    aMI[0][10].clip.height = (aMI.length * oPar.nHeight + (2 * 2 * oPar.nBorderWidth) + nSeparatorCount);
    aMI[0][10].clip.width = (nMaxWidth + (2 * 2 * oPar.nBorderWidth) + (2 * oPar.nLeftRightPadding) + oPar.nRightSpace);
    aMI[0][10].bgColor = '#BBBBBB';

    aMI[0][11] = new Layer(500, window);
    aMI[0][11].left = (oPar.nStartLeftPos - oPar.nBorderWidth + 100 * nI);
    aMI[0][11].top = (oPar.nStartTopPos - oPar.nBorderWidth);
    aMI[0][11].clip.height = (aMI.length * oPar.nHeight + (2 * oPar.nBorderWidth) + nSeparatorCount);
    aMI[0][11].clip.width = (nMaxWidth + (2 * oPar.nBorderWidth) + (2 * oPar.nLeftRightPadding) + oPar.nRightSpace);
    aMI[0][11].bgColor = 'white';

    var nHeightPos = oPar.nStartTopPos;
    for(nIndex = 0; nIndex < aMI.length; nIndex++) {
      strLayerTxt = '<table border="0" height="' + oPar.nHeight + '" width="100%"><tr><td><font face="' + oPar.strFont+ '" color="white" point-size="7.5"><b>' + aMI[nIndex][0] + '</b></font></td></tr></table>';
      aMI[nIndex][8] = new Layer(500, window);
      aMI[nIndex][8].document.write(strLayerTxt);
      aMI[nIndex][8].document.close();
      aMI[nIndex][8].left = (oPar.nStartLeftPos + 100 * nI);
      aMI[nIndex][8].clip.left = 0;
      aMI[nIndex][8].top = nHeightPos;
      aMI[nIndex][8].clip.height = oPar.nHeight;
      aMI[nIndex][8].clip.width = nMaxWidth + 2 * oPar.nLeftRightPadding + oPar.nRightSpace;
      aMI[nIndex][8].bgColor = '#ffcc33';

      aMI[nIndex][9] = new Layer(500, window);
      aMI[nIndex][9].reference = aMI[nIndex][8];
      aMI[nIndex][9].address = new String(aMI[nIndex][2]);
      aMI[nIndex][9].nIndex = new String(nI);
      aMI[nIndex][9].captureEvents(Event.MOUSEUP);
      aMI[nIndex][9].onmouseup = function() { window.location.href = this.address; };
      aMI[nIndex][9].onmouseover = function() { showMenu(this, -1); }; //      = function() { this.reference.bgColor = '#FF5F11'; };
      aMI[nIndex][9].onmouseout = function() { hideMenu(this, -1); };  //      = function() { this.reference.bgColor = '#990000'; };
      aMI[nIndex][9].left = (oPar.nStartLeftPos + 100 * nI);
      aMI[nIndex][9].top = nHeightPos;
      aMI[nIndex][9].clip.height = oPar.nHeight;
      aMI[nIndex][9].clip.width = nMaxWidth + 2 * oPar.nLeftRightPadding + oPar.nRightSpace;

      if(aMI[nIndex][3])
        nHeightPos += (oPar.nHeight + 1);
      else
        nHeightPos += (oPar.nHeight);
    }
    isMenuPrepared[nI] = true;
  } // end of NN4
  else if(isDOM) {
    miMenuItem = document.createElement('div');
    miMenuItem.id = aMI[0][4] + oPar.strBack1;
    miMenuItem.style.left = (oPar.nStartLeftPos - (2 * oPar.nBorderWidth) + 100 * nI) + 'px';
    miMenuItem.style.top = (oPar.nStartTopPos - (2 * oPar.nBorderWidth)) + 'px';
    miMenuItem.style.height = oPar.nHeight + 'px';
    miMenuItem.style.position = 'absolute';
    miMenuItem.style.background = '#BBBBBB';
    miMenuItem.style.borderWidth = '0px 0px 0px 0px';
    miMenuItem.style.visibility = 'hidden';
    document.body.appendChild(miMenuItem);

    miMenuItem = document.createElement('div');
    miMenuItem.id = aMI[0][4] + oPar.strBack2;
    miMenuItem.style.left = (oPar.nStartLeftPos - (1 * oPar.nBorderWidth) + 100 * nI) + 'px';
    miMenuItem.style.top = (oPar.nStartTopPos - (1 * oPar.nBorderWidth)) + 'px';
    miMenuItem.style.height = oPar.nHeight + 'px';
    miMenuItem.style.position = 'absolute';
    miMenuItem.style.background = 'black';
    miMenuItem.style.borderWidth = '0px 0px 0px 0px';
    miMenuItem.style.visibility = 'hidden';
    document.body.appendChild(miMenuItem);

    aResult = [0, oPar.nStartTopPos];
    aMI[0][6] = oPar.nStartLeftPos + nI * 100;
    for(var nIndex = 0; nIndex < aMI.length; nIndex++) {
      aMI[nIndex][7] = aResult[1];
      aResult = (nIndex) ? drawMenuItem(aMI[nIndex][0], aMI[nIndex][2], aMI[nIndex][4], aMI[nIndex - 1][3], aMI[nIndex][3], aMI[0][6], aMI[nIndex][7], aResult[0], nI)
                         : drawMenuItem(aMI[nIndex][0], aMI[nIndex][2], aMI[nIndex][4], 0, aMI[nIndex][3], aMI[0][6], aMI[nIndex][7], aResult[0], nI);
      document.getElementById(aMI[nIndex][4]).onmouseover = function() { showMenu(this, -1); };
      document.getElementById(aMI[nIndex][4]).onmouseout = function() { hideMenu(this, -1); };
      document.getElementById(aMI[nIndex][4]).style.zIndex = oPar.nzIndexMin + (100 * nI) + nIndex;
      document.getElementById(aMI[nIndex][4] + oPar.strLink).style.zIndex = oPar.nzIndexMin + (100 * nI) + nIndex + 1;
    }
    document.getElementById(aMI[0][4] + oPar.strBack1).style.width = aResult[0] + (4 * oPar.nBorderWidth);
    document.getElementById(aMI[0][4] + oPar.strBack1).style.height = aResult[1] - oPar.nStartTopPos + (4 * oPar.nBorderWidth) + 1;
    document.getElementById(aMI[0][4] + oPar.strBack1).style.zIndex = oPar.nzIndexMin - (nI * 10) - 2;
    document.getElementById(aMI[0][4] + oPar.strBack2).style.width = aResult[0] + (2 * oPar.nBorderWidth);
    document.getElementById(aMI[0][4] + oPar.strBack2).style.height = aResult[1] - oPar.nStartTopPos + (2 * oPar.nBorderWidth) + 1;
    document.getElementById(aMI[0][4] + oPar.strBack2).style.zIndex = oPar.nzIndexMin - (nI * 10) - 1;

    for(var nIndex = 0; nIndex < aMI.length; nIndex++) {
      document.getElementById(aMI[nIndex][4]).style.width = aResult[0];
      document.getElementById(aMI[nIndex][4] + oPar.strLink).style.width = aResult[0];
    }
    isMenuPrepared[nI] = true;
  }

  return true;
}


function drawMenuItem(strText, strLink, strID, bUpSeparator, bDownSeparator, nLeft, nTop, nMax, nIndex) {

  miMenuItem = document.createElement('a');
  miMenuItem.id = strID;
  miMenuItem.href = strLink;
  miMenuItem.style.left = nLeft + 'px';
  miMenuItem.style.top = nTop + 'px';
  miMenuItem.style.height = oPar.nHeight + 'px';
  miMenuItem.style.position = 'absolute';
  miMenuItem.style.background = '#ffcc33';
  miMenuItem.style.width = '350px';
  if(bUpSeparator) miMenuItem.style.borderWidth = '1px 0px 0px 0px';
  else miMenuItem.style.borderWidth = '0px 0px 0px 0px';
  miMenuItem.style.borderColor = 'black';
  miMenuItem.style.borderStyle = 'solid';
  miMenuItem.style.visibility = 'hidden';
  miMenuItem.style.textDecoration = 'none';
  miMenuItem.innerHTML = '';
  document.body.appendChild(miMenuItem);

  miMenuItem = document.createElement('div');
  miMenuItem.id = strID + oPar.strLink;
  miMenuItem.style.position = 'absolute';
  miMenuItem.style.left = '0px';
  miMenuItem.style.top = '0px';
  miMenuItem.style.height = oPar.nHeight + 'px';
  miMenuItem.style.fontSize = '7.5pt';
  miMenuItem.style.color = 'black';
  miMenuItem.style.fontFamily = oPar.strFont;
  miMenuItem.style.fontWeight = 'bold';
  miMenuItem.style.borderWidth = '0px 0px 0px 0px';
  miMenuItem.style.visibility = 'hidden';
  miMenuItem.style.padding = oPar.nTopBottomPadding + 'px ' + (oPar.nLeftRightPadding + oPar.nRightSpace) + 'px ' + oPar.nTopBottomPadding + 'px ' + oPar.nLeftRightPadding + 'px';
  if(isIE) miMenuItem.style.cursor = 'hand';
  else miMenuItem.style.cursor = 'pointer';
  miMenuItem.innerHTML = strText;
  document.getElementById(strID).appendChild(miMenuItem);

  return [Math.max(nMax, document.getElementById(strID + oPar.strLink).offsetWidth), nTop + oPar.nHeight - 1];
}


function runMenus() {

  if(!isMenuPrepared[aMenuItems.length - 1]) return false;
  if(isModifying)  return true;

  var bIsOpen = false;
  for(var nIndex = 0; nIndex < aMenuItems.length; nIndex++)
    if((isMenuToHide[nIndex]) && isMenuOpen[nIndex]) {
      hideMenuItems(nIndex);
      isMenuOpen[nIndex] = false;
    }
    else if((!isMenuToHide[nIndex]) && (!isMenuOpen[nIndex])) {
      showMenuItems(nIndex);
      isMenuOpen[nIndex] = true;
      bIsOpen = true;
    }
//  if(bIsOpen) tmOut = setTimeout('runMenus()', 4 * oPar.nMiliseconds);
//  else tmOut = setTimeout('runMenus()', oPar.nMiliseconds);
  return true;
}


function showMenuItems(nIndex) {
  
  var aMI = aMenuItems[nIndex];
  for(var nIndex = 0; nIndex < aMI.length; nIndex++) {
    if(isNN4) {
      aMI[nIndex][8].hidden = false;
      aMI[nIndex][9].hidden = false;
    }
    else if(isDOM) {
      document.getElementById(aMI[nIndex][4]).style.visibility = 'visible';
      document.getElementById(aMI[nIndex][4] + oPar.strLink).style.visibility = 'visible';
    }
  }
  if(isNN4) {
    aMI[0][10].hidden = false;
    aMI[0][11].hidden = false;
  }
  else if(isDOM) {
    document.getElementById(aMI[0][4] + oPar.strBack1).style.visibility = 'visible';
    document.getElementById(aMI[0][4] + oPar.strBack2).style.visibility = 'visible';
  }
  return true;
}


function hideMenuItems(nIndex) {

  var aMI = aMenuItems[nIndex];
  for(var nIndex = 0; nIndex < aMI.length; nIndex++) {
    if(isNN4) {
      aMI[nIndex][8].hidden = true;
      aMI[nIndex][9].hidden = true;
    }
    else if(isDOM) {
      document.getElementById(aMI[nIndex][4]).style.visibility = 'hidden';
      document.getElementById(aMI[nIndex][4] + oPar.strLink).style.visibility = 'hidden';
    }
  }
  if(isNN4) {
    aMI[0][10].hidden = true;
    aMI[0][11].hidden = true;
  }
  else if(isDOM) {
    document.getElementById(aMI[0][4] + oPar.strBack1).style.visibility = 'hidden';
    document.getElementById(aMI[0][4] + oPar.strBack2).style.visibility = 'hidden';
  }
  return true;
}


function showMenu(el, nIndex) {

  if(!isMenuPrepared[aMenuItems.length - 1]) return false;
/*
  if(isDOM)
    if(document.body.offsetWidth != oPar.nScreenWidth)
      if(document.getElementById(oPar.strStartID + (aMenuItems.length - 1))) {
        if(tmOut) clearInterval(tmOut); moveMenus(); tmOut = setInterval('runMenus()', oPar.nMiliseconds); oPar.nScreenWidth = document.body.offsetWidth; }
*/
  isModifying = true;
  if(isDOM)
    if(document.body.offsetWidth != oPar.nScreenWidth) {
      moveMenus(); oPar.nScreenWidth = document.body.offsetWidth; }

  if(nIndex == -1) {
    if(isNN4) {
      el.reference.bgColor = '#FF5F11';
      nI = el.nIndex;
    }
    else if(isDOM) {
      el.style.background = '#FF5F11';
      nI = Math.round((el.style.zIndex - oPar.nzIndexMin) / 100);
      window.status = aMenuItems[nI][el.style.zIndex % 100][1];
    }
  }
  else {
    nI = nIndex;
    window.status = aMenuItems[nI][0][5];
  }
  isMenuToHide[nI] = false;
  isModifying = false;
  return true;
}


function hideMenu(el, nIndex) {
  
  if(!isMenuPrepared[aMenuItems.length - 1]) return false;

  isModifying = true;
  window.status = 'Done';
  if(nIndex == -1) {
    if(isNN4) {
      el.reference.bgColor = '#ffcc33';
      nI = el.nIndex;
    }
    else if(isDOM) {
      el.style.background = '#ffcc33';
      nI = Math.round((el.style.zIndex - oPar.nzIndexMin) / 100);
    }
  }
  else {
    nI = nIndex;
  }
  isMenuToHide[nI] = true;
  isModifying = false;
  return true;
}


function _getLeft(tag) {
  return (tag.offsetParent.nodeName == 'BODY') ? (tag.offsetLeft) : (tag.offsetLeft + _getLeft(tag.offsetParent));
}

/*
function _getTop(tag) {
  return (tag.offsetParent.nodeName == 'BODY') ? (tag.offsetTop) : (tag.offsetTop + _getTop(tag.offsetParent));
}
*/

function getLeft(tag) {
  return (isDOM) ? _getLeft(tag) : tag.pageX;
}


function getTop(tag) {
  return oPar.nAlwaysTop;
//  return (isDOM) ? _getTop(tag) : tag.pageY;
}