/*
	mailto:eberhard.loh@satama.de

	i see the navigation level 1 as level 0
	so only the active part is handled as level 1 & level 2;
	the level 0 items are content of lyrTop & lyrBot...
!!!!
	do NOT place any whitespaces incl. linefeed before a </div>.
	it will result in a wrong height calculation for lyr*.height
	(& mayby other)
*/

// 7.2.2002/Kalevi Havumäki/Image Domain Path hardcoded!
//var imageDomainPath = 'http://image.club.nokia.com';
var imageDomainPath = '';
if (window.location.protocol=='http:') { imageDomainPath = 'http://image.club.nokia.com'; }
if (window.location.protocol=='https:') { imageDomainPath = ''; }

var	// these will store...
 lockedMI= 0,		// the autoOpened level-1-navi (MainItem) to prevent it become closed
 lockedSI= 'noLock';	// the name of the level-2-img (SubItem) without rollover-effect

function bitVal(bitNo) { return(1<< (bitNo- 1)); }
function setBit(bitMask, bitNo) { return(bitMask| bitVal(bitNo)); }
function rstBit(bitMask, bitNo) { return(bitMask& ~bitVal(bitNo)); }
function tstBit(bitMask, bitNo) { return(0< (bitMask& bitVal(bitNo))); }

if (document.layers) {
 var pre= 'document.', post= '', propHeight= '.clip.height'; }
else {
 var pre= 'document.all.', post= '.style', propHeight= '.offsetHeight'; }

var
 imgDown=	imageDomainPath + '/content/europe/const_pics/down1.gif',
 imgUp=		imageDomainPath + '/content/europe/const_pics/up1.gif',
 imgOff=	imageDomainPath + '/content/europe/const_pics/off1.gif',
 imgOn=		imageDomainPath + '/content/europe/const_pics/on1.gif',
 offsetX=	30,
 offsetY=	54,
 sub1prefix=	'm',
 sub2prefix=	's',
 subItems=	new Array(),
 visibleSubs=	0;		// used as bitmask !!!

function getHeight(lyrName) {
 return(eval(pre+ lyrName+ propHeight));
}

function drJekyll(lyrName, posX, posY, showIt) {
 eval(pre+ lyrName+ post+ '.left='+ posX);
 eval(pre+ lyrName+ post+ '.top='+ posY);
 if (showIt)
  eval(pre+ lyrName+ post+ '.visibility=\'visible\'');
}

function mrHyde(lyrName) {
 eval(pre+ lyrName+ post+ '.visibility=\'hidden\'');
}

function preparePage(autoOpen, lockSub) {
 var ofsZ= 0;
 drJekyll('lyrContent', 0, 0, true);
 drJekyll('lyrTop', offsetX, offsetY, true);
 offsetY+= getHeight('lyrTop');
 var ofsY= offsetY;
 if (post== '') {
  for (var ix= 0; ix< document.layers.length; ix++) {
   if (document.layers[ix].name.indexOf(sub1prefix)== 0) {
    drJekyll(document.layers[ix].name, offsetX, ofsY, true);
    ofsY+= getHeight(document.layers[ix].name);
   }
   else
    if (document.layers[ix].name.indexOf(sub2prefix)== 0) {
     subItems[subItems.length]= getHeight(document.layers[ix].name);
     ofsZ+= subItems[subItems.length- 1];
    }
  }
 }
 else {
  for (var ix= 0; ix< document.all.length; ix++)
   if (document.all[ix].tagName== 'DIV') {
    if (document.all[ix].id.indexOf(sub1prefix)== 0) {
     drJekyll(document.all[ix].id, offsetX, ofsY, true);
     ofsY+= getHeight(document.all[ix].id);
    }
    if (document.all[ix].id.indexOf(sub2prefix)== 0) {
     subItems[subItems.length]= getHeight(document.all[ix].id)
     ofsZ+= subItems[subItems.length- 1];
    }
   }
 }
 drJekyll('lyrBot', offsetX, ofsY, true);
 ofsY+= getHeight('lyrBot');
 ofsZ+= ofsY;
 var ofsC= getHeight('lyrContent');
 if (ofsZ<= ofsC)
  ofsZ= ofsC;
 else {
  var whiteH= ofsZ- ofsC;
  /* createLayer('lyrWhite', null, 0, 0, null, null, '<table cellpadding=0 cellspacing=0 border=0><tr><td width=1 height="'+ whiteH+ '" bgcolor="#8D8D8D"><img src="../../content/europe/const_pics/1x1.gif" width=1 height="'+ whiteH+ '" border=0></td><td width='+(620-30)+' height="'+ whiteH+ '" bgcolor=white><img src="../../content/europe/const_pics/1x1.gif" width="590" height="'+ whiteH+ '" border=0></td></tr></table>', null, 'hidden', '0'); */
  createLayer('lyrWhite', null, 0, 0, null, null, '<table cellpadding=0 cellspacing=0 border=0><tr><td width=1 height="'+ whiteH+ '" bgcolor="#8D8D8D"><img src="' + imageDomainPath + '/content/europe/const_pics/1x1.gif" width=1 height="'+ whiteH+ '" border=0></td><td width='+(620-30)+' height="'+ whiteH+ '" bgcolor=white><img src="' + imageDomainPath + '/content/europe/const_pics/1x1.gif" width="590" height="'+ whiteH+ '" border=0></td></tr></table>', null, 'hidden', '0');
  drJekyll('lyrWhite', offsetX- 1, ofsC, true);
 }
 drJekyll('lyrCopy', offsetX- 1, ofsZ, true);
 if (0< subItems.length)
  itemHeight= getHeight('m1');
 if ((autoOpen) && (0< autoOpen)) {
  controlSub(autoOpen);
  lockedMI= autoOpen;
 }
 if ((lockSub) && (0< lockSub)) {
  var lockThis= 'kuva'+ autoOpen+ 'x'+ lockSub;
  cI(sub2prefix+ autoOpen, lockThis, imgOn);
  lockedSI= lockThis;
 }
 else {
  lockedSI= 'noLock';
 }
}

function cI(thaLyr, thaImg, thaSrc) { // cI means changeImage; abbreviated to shorten the onMouseO...="cI();"
 if (thaImg!= lockedSI) {
  if (document.layers)
   var img= eval('document.'+ thaLyr+ '.document.'+ thaImg);
  else
   var img= eval('document.all.'+ thaImg);
  img.src= thaSrc;
 }
}

function controlSub(nUm) {
 if (nUm!= lockedMI) {
  if (tstBit(visibleSubs, nUm)) {
   visibleSubs= rstBit(visibleSubs, nUm);
   cI('m'+ nUm, 'kuva'+ nUm, imgDown);
  }
  else {
   visibleSubs= setBit(visibleSubs, nUm);
   cI('m'+ nUm, 'kuva'+ nUm, imgUp);
  }
  mrHyde('lyrBot');
  var ofsY= offsetY;
  for (var ix= 0; ix< subItems.length; ix++) {
   drJekyll('m'+ (ix+ 1), offsetX, ofsY, true);
   ofsY+= itemHeight;
   if (tstBit(visibleSubs, ix+ 1)) {
    drJekyll('s'+ (ix+ 1), offsetX, ofsY, true);
    ofsY+= subItems[ix];
   }
   else
    mrHyde('s'+ (ix+ 1));
  }
  drJekyll('lyrBot', offsetX, ofsY, true);
 }
}
