_dom = (document.getElementById) ? true : false;
_nn4 = (document.layers) ? true : false;
_ie = (document.all) ? true : false;
_ie4 = _ie && !_dom;
_opera = (window.opera) ? true : false;

var debug = false;
var rozw = 0;
var podrozw = 0;
var podpodrozw = 0;
var zw = true;
var curRoz=-1;
var selItem=0;


	if(_ie4){window.onresize = resizeIE;}

	if(_dom) {
		_oknoW = window.innerWidth;
		_oknoH = window.innerHeight;
	}



	if(_dom){window.onresize = resizeNN;}

	if(_nn4 ) document.captureEvents(Event.MOUSECLICK);
	else document.onclick = mouseClick;

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}


function mouseClick(e) {
//if (debug) alert('mouseclick');
if (!zwin || !roz) { return;}

	if(_nn4) {
		zwin(rozw);
		rozw = 0;
	} else if (e) {
		mg = document.getElementById('menu1poziom');
		if (!mg) return
		sx = e.pageX;
		sy = e.pageY;
		sx = e.pageX;
		sy = e.pageY;
		mgw = mg.offsetLeft+mg.offsetWidth;
		mgh = mg.offsetTop+mg.offsetHeight+40;

		if( (sx > mg.offsetLeft) && (sx < mgw) && (sy > mg.offsetTop) && ( sy < mgh)) {
		}else{
		  zwin(rozw);
		  rozw = 0;		
		//  podzwin(podrozw);
		//  podpodzwin(podpodrozw);
		//  podrozw = 0;		
		//  podpodrozw = 0;		
		}
	} else if (event) {
		if(event.srcElement.parentElement.name != 'menunav') {
			zwin(rozw);
			rozw = 0;
			 // podzwin(podrozw);
			//  podpodzwin(podpodrozw);
			//  podrozw = 0;		
			//  podpodrozw = 0;		
	    }
	}
	return true;
}

function roz(numer) {
    podzwin(podrozw);
    podrozw = 0;
//if (debug) alert('roz '+numer);

//  document.getElementById('poz'+numer).className = 'menu1on';
  curRoz=numer;
  if(_ie4) {
	costam = document.all['menuplace'];
	if (!costam) return;
    yy = costam.offsetTop + costam.scrollHeight + 1;
  } else {
	costam = document.getElementById('menuplace');
	if (!costam) return;
    yy = costam.offsetTop +6 ;
  }

if (!zwin) 
	return;

  yy += 26;

  if(rozw != numer || zw) zwin(rozw);
  if(podrozw != numer || zw) podzwin(podrozw);
  		 
  if(rozw == numer && zw) rozw=0;
  else if(numer != 0) {
	naglowek = document.getElementById('poz'+numer);
	if (!naglowek) return;
	bla = naglowek.offsetLeft + costam.offsetLeft - 1;
    mn = "menu" + numer + "Div";
    moveTo(mn, bla, yy);
    show(mn);			
    rozw=numer;
  }
}

function podroz(numer, nagl) {
if (podrozw > 0)
    podzwin(podrozw);
if (podpodrozw > 0)
    podpodzwin(podrozw);
//if (debug) alert('roz '+numer);

//  document.getElementById('poz'+numer).className = 'menu1on';
  curRoz=numer;
  if(_ie4) {
	costam = document.all['menuplace'];
	if (!costam) return;
    yy = costam.offsetTop + costam.scrollHeight + 1;
  } else {
	costam = document.getElementById('menuplace');
	if (!costam) return;
    yy = costam.offsetTop + 6 ;
  }

  yy += 26;

// a teraz wyliczam y ;-)
var ile = nagl.charAt(2);
for (i = 1; i < ile; i++)
{
	yy += 20;
}

if(numer != 0) {
	naglowek = document.getElementById("menu" + nagl.charAt(1) + "Div");
	bla = naglowek.offsetLeft + naglowek.offsetWidth;
	mn = "podmenu" + numer + "Div";
	moveTo(mn, bla, yy);
    show(mn);			
    podrozw=numer;
  }
}

function podroz2(numer, ile) {
//alert('numer:'+numer+'   nagl:'+nagl);
//if (podrozw > 0)
//    podzwin(podrozw);
//if (debug) alert('roz '+numer);

//  document.getElementById('poz'+numer).className = 'menu1on';
 // curRoz=numer;
  if(_ie4) {
	costam = document.all['menuplace'];
	if (!costam) return;
    yy = costam.offsetTop + costam.scrollHeight + 1;
  } else {
	costam = document.getElementById('menuplace');
	if (!costam) return;
    yy = costam.offsetTop + 6 ;
  }
  yy += 20;

// a teraz wyliczam y ;-)
var il = parseInt(ile);
for (i = 1; i < il; i++)
{
	yy += 20;
}

if(numer != 0) {
	naglowek = document.getElementById("podmenu" + numer + "Div");
	if (!naglowek) return;
	bla = naglowek.offsetLeft + naglowek.offsetWidth;
	mn = "secpodmenu" + numer + "Div";
//	alert(mn);
	moveTo(mn, bla, yy);
    show(mn);	
    podpodrozw=numer;
  }
}

function zwin(numer) {

  if (podrozw)
  {
    podzwin(podrozw);
	podrozw = 0;
  }
  if(podpodrozw){
  	podpodzwin(podpodrozw);
  	podpodrozw = 0;
  }
  
//document.getElementById('poz'+numer).className = 'menu1off';
//if (debug) alert('zwin '+numer);
  if(numer != 0) {
    mn = "menu" + numer + "Div";
    hide(mn);
    if(_ie4) 
		if(selItem != numer) 
			document.all['m'+numer].className = "white";
	menuOut();				
  }
}

function podzwin(numer, ble) {
//document.getElementById('poz'+numer).className = 'menu1off';
//if (debug) alert('zwin '+numer);
  if(numer != 0) {
    mn = "podmenu" + numer + "Div";
    hide(mn);
    if(_ie4) 
		if(selItem != numer) 
			document.all['m'+numer].className = "white";
	menuOut();				
  }
}
function podpodzwin(numer) {

  if(numer != 0) {
    mn = "secpodmenu" + numer + "Div";
    hide(mn);
    if(_ie4) 
		if(selItem != numer) 
			document.all['m'+numer].className = "white";
	menuOut();				
  }
}

var menuSel = null;

function menuOver(id) {
	if(menuSel != null) document.getElementById(menuSel).className ="linkmenuoff"; 
	document.getElementById(id).className = "linkmenuon";
	menuSel = id;
}

function menuOver2(id,number) {
	if(menuSel != null) document.getElementById(menuSel).className ="linkmenuoff"; 
	document.getElementById(id).className = "linkmenuon";
	menuSel = id;

	if(podpodrozw > 0 ){		
		podpodzwin(podpodrozw);
		podpodrozw = 0;
	}
}

function menuOverGl(id) {
	menuOver(id);
    if(podrozw != id || zw) podzwin(podrozw);

}

function podmenuOver(id, poz) {
	if(menuSel != null) document.getElementById(menuSel).className ="linkmenuoff"; 
	document.getElementById(id).className = "linkmenuon";
	var podmenus = 'podmenu'+poz+'Div';
	show(podmenus,'');
	//alert(podmenus);
	//document.getElementById(podmenus).style.visibility = 'visible';
	menuSel = id;

}

function menuOut() {
	if(menuSel != null) document.getElementById(menuSel).className = "linkmenuoff";
	menuSel = null;
}


function moveTo(ident,x,y,nest) {
//if (debug) alert('moveto '+ident);

  if(_nn4) {
    nest ? document.layers[nest].document.layers[ident].left = x : document.layers[ident].left = x;
    nest ? document.layers[nest].document.layers[ident].top = y : document.layers[ident].top = y;
  } else if(_ie4) {
    document.all[ident].style.left = x;
    document.all[ident].style.top = y;
  } else if(_dom) {
		aa = document.getElementById(ident);
		if (!aa) return;
		aa.style.left = x;
		aa.style.top = y;
	}
}


function show(ident,nest) {
//if (debug) alert('show '+ident);

  if(_nn4) {  
    nest ? document.layers[nest].document.layers[ident].visibility = "show" : document.layers[ident].visibility = "show";
  } else if(_ie4) {  
    document.all[ident].style.visibility = "visible";
  } else if(_dom) {
    aa = document.getElementById(ident);
	if (!aa) return;
    aa.style.visibility = "visible";	
	}
}

function hide(ident,nest) {
  if(_nn4) {  
    nest ? document.layers[nest].document.layers[ident].visibility = "hide" : document.layers[ident].visibility = "hide";
  } else if(_ie4) {
    document.all[ident].style.visibility = "hidden";
  } else if(_dom) {
    aa = document.getElementById(ident);
	if (!aa) return;
    aa.style.visibility = "hidden";	
	}
}

function resizeIE() {
 	costam = document.getElementById('menuplace');
	if (!costam) return;
	menuLeft = (_dom) ? costam.style.left : costam.offsetLeft;
	menuTop = (_dom) ? costam.style.top : costam.offsetTop;
}

function resizeNN() {
  if(window.innerWidth != _oknoW || window.innerHeight != _oknoH) { 
    window.location.reload();
  }
}


var hidden = true;

function flipAll(){
	tab = document.getElementsByTagName('p');

	if (hidden) {
		hidden = false;
		cName = 'pmshown';
		disp = 'block';
	} else {
		hidden = true;
		cName = 'pmhidden';
		disp = 'none';
	}

	for (ii=0; ii < tab.length; ii++)
		if (tab[ii].className=='pmshown' || tab[ii].className=='pmhidden'){
			tab[ii].className = cName;
			tab[ii].style.display = disp;
		}

	
}


function onmo(xx) {
	if (!roz) return;
	zw=true; 
	roz(xx); 
	zw=false; 
}

function otworz(sciezka, szer, wys) {
 myWindow = window.open("", "_blank", 'width='+szer+',height='+wys+',scrollbars=no,status=no')
 myWindow.document.write("<html><head><title>Hetman</title></head><body style=\"padding:0; margin:0; background-color: white\"><object type=\"application/x-shockwave-flash\" data=\""+sciezka+"\" width=\""+szer+"\" height=\""+wys+"\"><param name=\"allowScriptAccess\" value=\"sameDomain\" /><param name=\"movie\" value=\""+sciezka+"\" /><param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /></object></body></html>")
 myWindow.document.close() 
}